I'm having a weird problem. I'm having a Xamarin Android application and Enabling foreground dispatch for NFC Scanning like this:
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);
So when the intent filter and tech list as null, it is expected that the OS dispatches the tag scanned to our application irrespective of the action (NDEF_DISCOVERED, TECH_DISCOVERED, TAF_DISCOVERED). I'm scanning the same NDEF tag multiple times. Most of the times the action is NDEF_DISCOVERED and the NFC tag is dispatched to our app via New Intent. However, sometimes the action is TECH_DISCOVERED (as per the Android device logs) and in this case, the NFC tag is not dispatched the our application and the default Android Tag scanned page is displayed.
I have also tried to add all the actions explicitly in the intent filter along with the tech list like below but the behavior is the same. It is also weird that I have 2 devices and this issue occurs only on one device
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);
Any leads will be appreciated. Thanks in advance!