我有一个奇怪的问题。我有一个 Xamarin Android 应用程序并为 NFC 扫描启用前台调度,如下所示:
Intent intent = new Intent(mainActivity.ApplicationContext, mainActivity.Class);
intent.SetFlags(ActivityFlags.SingleTop);
intent.PutExtra("NFCIntent", true);
PendingIntent pendingIntent = PendingIntent.GetActivity(mainActivity.ApplicationContext, 0, intent, 0);
nfcAdapter.EnableForegroundDispatch(mainActivity, pendingIntent, null, null);
因此,当意图过滤器和技术列表为空时,预计操作系统会将扫描的标签分派给我们的应用程序,而不管操作(NDEF_DISCOVERED、TECH_DISCOVERED、TAF_DISCOVERED)如何。我正在多次扫描同一个 NDEF 标签。大多数情况下,操作是 NDEF_DISCOVERED,NFC 标签通过 New Intent 发送到我们的应用程序。但是,有时该操作是 TECH_DISCOVERED(根据 Android 设备日志),在这种情况下,我们的应用程序不会调度 NFC 标签,并且会显示默认的 Android 标签扫描页面。
我还尝试在意图过滤器中显式添加所有操作以及如下所示的技术列表,但行为是相同的。我有两台设备也很奇怪,这个问题只发生在一台设备上
Intent intent = new Intent(mainActivity.ApplicationContext, mainActivity.Class);
intent.SetFlags(ActivityFlags.SingleTop);
intent.PutExtra("NFCIntent", true);
var tagDetected = new IntentFilter(NfcAdapter.ActionTagDiscovered);
var ndefDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered);
var techDetected = new IntentFilter(NfcAdapter.ActionTechDiscovered);
var filters = new[] { ndefDetected, tagDetected, techDetected };
PendingIntent pendingIntent = PendingIntent.GetActivity(mainActivity.ApplicationContext, 0, intent, 0);
var techlist = new string[][] {new string[]
{
"android.nfc.tech.IsoDep",
"android.nfc.tech.NfcA",
"android.nfc.tech.NfcB",
"android.nfc.tech.NfcF",
"android.nfc.tech.NfcV",
"android.nfc.tech.Ndef",
"android.nfc.tech.NdefFormatable",
"android.nfc.tech.MifareClassic",
"android.nfc.tech.MifareUltralight"
}
};
NDEF action and MimeTypePlainText OnNewIntent
nfcAdapter.EnableForegroundDispatch(mainActivity, pendingIntent, filters, techlist);
任何线索将不胜感激。提前致谢!