2016-09-05 61 views
-3

我正在开发一个关于nfc扫描的应用程序。无论如何,它会在接近NFC标签时启动活动(即使应用程序未运行)。 现在,我希望应用程序在打开应用程序时开始NFC扫描,并在关闭活动时关闭sanning。简而言之,我想为NFC扫描添加一个控制器。如何在关闭活动时停止android NFC扫描?

+1

我不完全理解你的问题,你想停止扫描nfc标签吗? –

回答

0

使用意图过滤器在扫描NFC标签时启动您的应用程序。见https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#filtering-intents

要扫描NFC标签您的应用程序运行时,使用[enableForegroundDispatch(https://developer.android.com/reference/android/nfc/NfcAdapter.html#enableForegroundDispatch(android.app.Activity,android.app.PendingIntent,android.content.IntentFilter [],java.lang.String中[] []))。

您可以通过致电disableForegroundDispatch停止扫描。您需要禁用onPause()中的前台分派。