0

My Cordova application reads NFC tags while in foreground using this plugin: https://github.com/ns0m/cordova-plugin-ns0m-nfc

While scanning, my application is in the foreground. But when a tag is read, my app's main activity is paused, and then resumed again shortly thereafter. Is there a way to prevent that? My app has logic that assumes a pause event means the user put the app in the background, and so it stops a bunch of internal app services. I don't want it to do that. I just want it to read the NFC tag and keep moving along in the foreground without interruption. iOS does that without a hitch. Is that possible in Android?

Thanks.

jacob
  • 2,762
  • 1
  • 20
  • 49
  • Natively on Android you can read a Tag without pausing the activity with `enableReaderMode`, not sure about a plugin for Cordova that uses the newer API – Andrew Mar 29 '23 at 23:23
  • Thanks @Andrew. There are some other stack overflows (e.g., https://stackoverflow.com/questions/33633736/whats-the-difference-between-enablereadermode-and-enableforegrounddispatch) that seems to indicate other issues using enableReaderMode. I ended up wrapping the idle event with logic that dispatches a different "realIdle" event only if the initial pause is not resumed within 1 second. That seems to work fine. – jacob Mar 30 '23 at 11:55
  • That answer is so old, the issues it raised were "only from Android 4.4 onwards", pre 4.4 devices are are such a small number of devices now it's not really an issue. It disables NFC peer to peer, that was removed in Android 10 anyway, so a minor issue as NFC peer to peer was not used much. `enableReaderMode` is much more reliable than using the intent based system, especially if writing to a Tag. – Andrew Mar 30 '23 at 12:06

0 Answers0