chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 556 forks source link

NFC plugin stops working if NFC is turned on without application restart #310

Closed Maduiini closed 6 years ago

Maduiini commented 6 years ago

OS: Android 7.0

NFC plugin no longer reads tags if the phone's NFC is turned off and then on again (or was off and is turned on). This problem persists until app restart or if onResume event is triggered, for example by going to lockscreen or another app and back. (Visiting the phone's dropdown quickmenu doesn't bring the app into background.) Also if the nfc plugin wasn't initialized at all (nfc off when starting app) the only fix is to restart the application to init it.

nfc.enabled returns "NFC_OK" even though it doesn't read anything and the plugin's startNfc is not called before onResume.

Could there be a way to dynamically initialize the plugin if it wasn't on? Currently only init and onResume methods can call startNfc and it cannot be called any other way from the js side since it's protected.

don commented 6 years ago

@Maduiini Is this still a problem? Are you seeing this on more than one device? I haven't seen this in the past, I can't replicate it on Samsung S8 with Android 8.0.0. (I don't have a Android 7.0 phone handy.)

Can you run with the AndroidStudio debugger and make sure onResume() is getting called?

Maduiini commented 6 years ago

OnResume() was only getting called when returning to the app from lockscreen/other apps. Not when visiting the dropdown-quickmenu.

Figured out a workaround by adding a BroadcastReceiver inside the plugin that listens to changes in the phone NFC and calls startNfc() / stopNfc(). This way it always changes the plugin state if NFC is turned off/on.

KreoDev commented 5 years ago

Hi there I'm having the same problem on Android 7.0. Could I please have more information on how to create this workaround, I have never really modified a plugin before.