okadan / flutter-nfc-manager

A Flutter plugin for accessing the NFC features on Android and iOS.
https://pub.dev/packages/nfc_manager
MIT License
208 stars 134 forks source link

Unable to detect NFC tag on Android #82

Closed Jsjskat closed 2 years ago

Jsjskat commented 2 years ago

Hi, I'm currently working on my first app implementing Nfc data exchange to retrieve data from an NfcV device. Unfortunately, I wasn't successful for now. It seems the NfcTagCallback from startSession method is not responding when I approach any type of Nfc device, as if it wasn't able to detect it, which is weird since other apps are able to detect those exact same devices.

Reader : Samsung Galaxy S10 Nfc device :

On build, I get this error though, but I am unable to interpret it. Is it where the problem is ?

I/Gralloc4(26680): mapper 4.x is not supported
W/Gralloc3(26680): mapper 3.x is not supported
I/gralloc (26680): Arm Module v1.0
W/Gralloc4(26680): allocator 4.x is not supported
W/Gralloc3(26680): allocator 3.x is not supported
I/ViewRootImpl@a173f02[MainActivity](26680): [DP] pdf(0) 1 android.view.ViewRootImpl.lambda$createFrameCompleteCallback$3$ViewRootImpl:4846 android.view.ViewRootImpl$$ExternalSyntheticLambda15.run:6 android.os.Handler.handleCallback:938 
I/ViewRootImpl@a173f02[MainActivity](26680): [DP] rdf()
D/ViewRootImpl@a173f02[MainActivity](26680): reportDrawFinished (fn: -1) 
I/ViewRootImpl@a173f02[MainActivity](26680): MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager(26680): startInputInner - Id : 0
I/InputMethodManager(26680): startInputInner - mService.startInputOrWindowGainedFocus
D/InputMethodManager(26680): startInputInner - Id : 0

Here's my read method for my NfcV device which I call on start :

void readNFC() {
    NfcManager.instance.startSession(
      onDiscovered: (NfcTag tag) async {
        final nfcv = NfcV.from(tag);
        print(nfcv?.identifier);
      },
    );
    NfcManager.instance.stopSession();
  }

I also correctly added all permissions necessary in my AndroidManifest.xml. Any idea is welcome, thanks !

Jsjskat commented 2 years ago

Found the issue ! It was an implementation from my side, the stopSession() method was called too soon. Changed the function and everything works as expected now ! Thank you for the package !