Activity 从另一个应用启动的 enableForegroundDispatch
enableForegroundDispatch for Activity launched from another app
我开发了一个带有 NFC 标签交互的应用程序。大多数时候应用程序必须忽略标签发现事件。当我的应用程序处于前台时,其他应用程序不应捕获标签发现事件。所以我使用 EnableForegroundDispatch 来处理它。
这很好用。我在 activity 的 onNewIntent 方法中处理了过多的 TAG_DISCOVERED 意图。
问题: 当我的 activity 从另一个应用程序启动时,enableForegroundDispatch 不工作。我在新 activity 的 onCreate 方法中收到 TAG_DISCOVERED 意图。
这是我的 foregroundDispatch
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);
}
可能与旗帜有关?请帮助
我的经验是,如果您启用带有所有标志的 ReaderMode(包括跳过 NDEF 检查),那么如果 运行 在前台,基本上任何卡类型的检测都会发送到您的应用程序。
以及 enableReaderMode
在 onResume 中,我有 Broadcaster Receiver 来启用 NFC 服务状态更改的 ReaderMode。
检查一些不同的标签,这似乎有效,但它们都是基于不同格式的 NfcA。正如 Whosebug 所证实的那样。com/questions/33633736/... 但似乎 Android 10 可能在 Kiosk 模式下存在时间问题
我开发了一个带有 NFC 标签交互的应用程序。大多数时候应用程序必须忽略标签发现事件。当我的应用程序处于前台时,其他应用程序不应捕获标签发现事件。所以我使用 EnableForegroundDispatch 来处理它。
这很好用。我在 activity 的 onNewIntent 方法中处理了过多的 TAG_DISCOVERED 意图。
问题: 当我的 activity 从另一个应用程序启动时,enableForegroundDispatch 不工作。我在新 activity 的 onCreate 方法中收到 TAG_DISCOVERED 意图。 这是我的 foregroundDispatch
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);
}
可能与旗帜有关?请帮助
我的经验是,如果您启用带有所有标志的 ReaderMode(包括跳过 NDEF 检查),那么如果 运行 在前台,基本上任何卡类型的检测都会发送到您的应用程序。
以及 enableReaderMode
在 onResume 中,我有 Broadcaster Receiver 来启用 NFC 服务状态更改的 ReaderMode。
检查一些不同的标签,这似乎有效,但它们都是基于不同格式的 NfcA。正如 Whosebug 所证实的那样。com/questions/33633736/... 但似乎 Android 10 可能在 Kiosk 模式下存在时间问题