我开发了具有NFC标签交互功能的应用。大多数时候,应用程序必须忽略标签发现事件。当我的应用程序为前台时,其他应用程序不应捕获标记迪斯科事件。因此,我使用EnableForegroundDispatch来处理该问题。
这很好。我在活动的onNewIntent方法中处理了过多的TAG_DISCOVERED意图。
问题:从另一个应用程序启动我的活动时,enableForegroundDispatch无法正常工作。我在新活动的onCreate方法中收到TAG_DISCOVERED意向。这是我的前景色]
if (nfcAdapter == null) { Log.w(TAG, "enableForegroundNfcDispatch: no nfcAdapter", new Exception()); return; } Log.d(TAG, "enableForegroundNfcDispatch: "); if (!nfcMonopolyMode) { if (nfcTagDiscoveryPendingIntent != null) { nfcAdapter.enableForegroundDispatch(this, nfcTagDiscoveryPendingIntent, nfcTagDiscoveryFilter, null); return; } IntentFilter discovery = new IntentFilter(ACTION_TAG_DISCOVERED); nfcTagDiscoveryFilter = new IntentFilter[]{discovery}; Intent nfcProcessIntent = new Intent(getBaseContext(), getClass()) .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); nfcTagDiscoveryPendingIntent = PendingIntent.getActivity(getApplicationContext(), REQUEST_CODE_NFC_DISCOVERED_TAG, nfcProcessIntent, 0); nfcMonopolyMode = true; nfcAdapter.enableForegroundDispatch(this, nfcTagDiscoveryPendingIntent, nfcTagDiscoveryFilter, null); }
可能与标志有关吗?请帮助
我开发了具有NFC标签交互功能的应用。大多数时候,应用程序必须忽略标签发现事件。当我的应用程序为前台时,其他应用程序不应捕获标记迪斯科事件。所以我用了...
我的经验是,如果使用所有标志启用了Reader模式(包括跳过NDEF检查,则如果在前台运行,则基本上将对任何卡类型的检测都发送到您的应用程序。