Android NFC scanning on home launcher app

62 Views Asked by At

I have an android app set as the default launcher of the device with :

 <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
      <category android:name="android.intent.category.HOME" />
      <category android:name="android.intent.category.DEFAULT" />
 </intent-filter>

I also have a BaseActivity that every activity of my app extends where i register for NFC reading :

 override fun onResume() {
   super.onResume()
   val manager: NfcManager = getSystemService(Context.NFC_SERVICE) as NfcManager
   nfcAdapter = manager.defaultAdapter
   if (nfcAdapter == null) {
      showMessage("NFC not supported on this device")
         return;
   }
   // Check if NFC is enabled
   if (nfcAdapter?.isEnabled == false) {
        showMessage("Enable NFC")

   }
   val options = Bundle()
       options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 200)

      nfcAdapter?.enableReaderMode(
           this,
           this,
           NfcAdapter.FLAG_READER_NFC_A or
           NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK ,
           options
        );
    }

If i restart the device and the app launches as the device launcher, when I scan a NFC it shows the "New Tag Collected" view from com.android.apps.tag.

After dismissing that and scanning again it works fine. Any idea on why that might happen.

Also my device is rooted so if anyone has an adb idea please say so.

I tried debugging, and logging and the onResume is called fine and the NFC adapter is enabled correctly, just the onTagReceived is not called the first time after restart. I also tried using

enableForegroundDispatch 

but still the same

0

There are 0 best solutions below