chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
715 stars 573 forks source link

nfc.addNdefListener() does not fire .subscribe() function #430

Open filipap opened 3 years ago

filipap commented 3 years ago

Good afternoon, I've been using your plugin to test communication between 2 android devices.
Here is the code I use to receive the message:

receiveValue() {
    this.nfc.addNdefListener(ev => console.log('event: ', ev)).subscribe((message) => {
        console.log(message)
    });
}

To send the message:

sendValue() {
      let value = this.ndef.textRecord('Hello World!');
      this.nfc.share([value]);
}

I'm using the Ionic Native version that's in the npm registry. After some testing I noticed 2 problems:

Any suggestions to solve this?

PaintedShepherd commented 3 years ago

same problem for me. the subscribe function is never fired so i cant read any nfc tags. =(

GilTos75 commented 2 years ago

I had the same problem, the subscribe function was never called for an Ndef tag. In my case the solution was to add the request NFC access in the android manifest as described here

https://developer.android.com/guide/topics/connectivity/nfc/nfc#manifest

I just added the line to the manifest, sync'ed the project and the event fired successfully without changes to the actual code.

archibald-picq commented 2 years ago

In my case (Android 11), I was missing one of the geolocation permission (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION)