On scanning the NFC tag, device opens the chose application dialog rather than the onNewIntent
callback. From log I can see the below line of code for NFC
START u0 {act=android.nfc.action.NDEF_DISCOVERED dat=https://sdm.nfcdeveloper.com/... cmp=android/com.android.internal.app.ResolverActivity (has extras)} from uid 1027
I’ve added NDEF_DISCOVERED in manifest with enableForegroundDispatch
, app is still not picking NDEF_DISCOVERED
action. Below is the code I’m using
Manifest:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
And in activty:
private fun enableForegroundMode() {
val filters = arrayOfNulls<IntentFilter>(1)
val techList = arrayOf<Array<String>>()
filters[0] = IntentFilter()
with(filters[0]) {
this?.addAction(NfcAdapter.ACTION_TAG_DISCOVERED)//ACTION_NDEF_DISCOVERED
this?.addAction(NfcAdapter.ACTION_TECH_DISCOVERED)//ACTION_NDEF_DISCOVERED
this?.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED)//ACTION_NDEF_DISCOVERED
this?.addCategory(Intent.CATEGORY_DEFAULT)
try {
this?.addDataType("*/*")
} catch (ex: IntentFilter.MalformedMimeTypeException) {
throw RuntimeException("Check your MIME type")
}
}
mPendingIntent = PendingIntent.getActivity(
this, 0, Intent(
this,
javaClass
).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), FLAG_IMMUTABLE
)
mAdapter.enableForegroundDispatch(this, mPendingIntent, filters, techList)
}
In onNewIntent
I’m just trying log the intent action.