revtel / react-native-nfc-manager

React Native NFC module for Android & iOS
MIT License
1.4k stars 318 forks source link

Minimal example provided in documentation works on IOS but does not detect tag on Android #747

Open kitkline opened 2 months ago

kitkline commented 2 months ago

Hi all, advice or help appreciated (ps - awesome tool!)

Following the documentation we have built NFC tag scanning into our app and works perfectly on IOS but on Android the tag is not read (to tag is ever returned from await NfcManager.getTag()

Checked - the phone is NFC capable and the app NFC tools on the phone can read the tag (i.e issue is in our code - not in the phone).

Checked - AndroidManifest.xml contains:

After the tech is launched by the user tapping the 'scan' button there is no error but scanning the tag does nothing. Pairing the phone with Android studio we see the following in logcat:

2024-09-19 23:05:01.901 14222-14419 ReactNativeNfcManager org.gearlog.app D isSessionAvailable: false 2024-09-19 23:05:01.905 14222-14419 ReactNativeNfcManager org.gearlog.app D registerTagEvent 2024-09-19 23:05:01.908 14222-14419 ReactNativeNfcManager org.gearlog.app I enableForegroundDispatch, enable = true

And then nothing else

Phone is Samsung A10 running Android 11 (it's a cheap old phone we used for physical testing - but should work given that NFC tools works?)

How can we generate more debug or logging to help resolve?

Code follows...


  async scanNFC() {
    try {
      alert('We see this message');
      await NfcManager.requestTechnology(NfcTech.Ndef);

      const tag = await NfcManager.getTag();
    alert('We never see this message');
       -> our tag parsing code follows but we never get to that as never get a tag

    } catch (ex) {
        -> our error alerting

      );
    } finally {
        NfcManager.cancelTechnologyRequest();
    }
  }
kitkline commented 2 months ago

To add further to this we have boiled the code down to the absolute minimum and the basic issue (Android) only is that 'await NfcManager.getTag()' simply never resolves. The NFCManager is running and once the app is on that screen the normal android phone default response to a nearby tag no longer occurs - so clearly the app has grabbed NFC as the manager starts - but when an tag is close NfcManager.getTag() does not resolve. Could this be something to do with how android sends the tag event on older phones (A10 running Android 11 which can run the app NFC tools just fine)

kitkline commented 2 months ago

To add further to this we have also tried on a Google Pixel 5 running Android 14 and found the minimal example works. In summary an Android 11 device does not work and an Android 14 does. We would like to support older devices so if it is possible to get some advice that would me much appreciated...

Many thanks for such an awesome module!

Cheers Kit

javix64 commented 1 week ago

hey @kitkline which kind of card are you using? what is the output of reading card in iPhone? is there any information about the card that you are trying to read?