-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error When App Starts from NFC Tag Scan Event #457
Comments
I do also experience this issue. The PR that you provided prevents indeed the NULL pointer exception, but in my opinion this is not really a solution, because this means it will simply not trigger the listener at all (because it is not send through the channel anymore). The scenario where I have this problem is as follows:
I initialize an eventlistener in the Did experience the same things @PowerOfM? |
@gercobrandwijk You bring up a valid point. I think a more thorough solution would be to enqueue the event and send it to the bridge once it's fully initialized. I'm actually using CapacitorJS instead of PhoneGap/Cordova, and the ndef data gets passed in as a launch-url to the app. So I haven't had any issues and a cold-start of the app from an NFC event works as expected. I hope you're able to figure it out! |
Watching this as I'm having similar issues when using PhoneGap/Cordova plugin in Capacitor 3 and Ionic 5. |
I ended up override the NfcPlugin.java with some custom code, please see this gist (contains 4 files including a README.md): https://gist.github.com/gercobrandwijk/e1ef9b2cb56a1cba17d5d0aa20876819 Basically after an npm install I run that The main problem that is solved in the gist/NfcPlugin.java is that the scanned NFC tag is not lost when the app is not started yet (which causes an exception in the 'normal' NfcPlugin.java code, see the comments above) by remembering the last scanned tag in the variable |
@gercobrandwijk That looks great! Would you be interested in submitting an PR? It also looks like other people are trying to tackle the same issue: #460 |
@PowerOfM - thanks for referencing my PR above. I took a slightly different approach: I enqueue the event and expose a new plugin API that allows fetching the scanned tag. I needed to do this because my app needs to perform further initialization after Cordova calls the ready event, so this pattern better matched my requirements. My app has been using the variation referenced in the PR for a few months now and have not run into any issues yet. Unfortunately, I don't think the PR has yet been looked at yet by the owner of the main repo. |
see chariotsolutions#457 (comment) ment-988285150
For anyone that looks for a bundled solution with Android 12 compat. This fork groups both fixes:
You can directly reference the branch in [...]
"dependencies": {
"phonegap-nfc": "somq/phonegap-nfc#fix/nfc-launch",
[...]
} Edit: proposed the PR as !470 as a reference even though commits are not really clean... |
When the app starts from an NFC tag scan event, the
channelCallback
is null, causing an NPE.The text was updated successfully, but these errors were encountered: