Closed chrizy closed 8 years ago
source added, Many Thanks
Try to replicate the problem without all of your additional code.. IE check to see if it's your code of the plugin that's bad.
Looking at things I'd guess it's your code *ducks...
@chrizy I'd expect that something isn't getting initialized correctly
I created a simple Angular + NFC app for debugging this. Can you try on your hardware? https://github.com/don/phonegap-nfc-issue144
I have the same issue as listed. It's not the code from @chrizy. I'm using Cordova 2.9.0 and the Phonegap build (online) with the latest NFC code library. Tablet is Nexus 7 with Android 4.4.4.
I managed to limit the library version to 0.4.8 which is an option supported by Adobe Build and the problem goes away. So appears to be with these later versions of NFC library.
@dclarkenz Does it still happen in your app if you use Cordova 3.5 or 3.6? (Cordova 2.9.0 is too old to support for open source stuff.)
Does https://github.com/don/phonegap-nfc-issue144 work on your hardware?
No. Tested with Cordova 2.9.0 and 3.5.0 (both thru Adobe Build) and the Android OS captures the tag not the app. I'm using the latest NFC library on the Adobe Build servers which I think is 0.5.1.
@dclarkenz My example fails on your Nexus 7? Is it the original Nexus 7 or the new one? I have an old Nexus 7 with 4.4.4. I'll have to try that tomorrow. Is your PhoneGap Build project public? The code I sent worked every time with my Nexus 5 and Galaxy Nexus built with Cordova 3.6. I'll try some more combinations to duplicate so we can solve this.
New Nexus 7 (2013 edition). I'll try on my 2012 version tonight for you. Try https://build.phonegap.com/apps/1123296/install
Found the same issue in my app.
If I only use addNdefListener:
I've tested 2 workarounds and they work fine (hope they won't have side effects):
@rogervinas does your first NFC scan open the app with an intent defined in the android manifest file? If so, the 2nd work around is the "official" way to do this.
@don I don't have any intent defined in the android manifest file related to NFC, should I have one if I am using addNdefListener? I am applying the 2nd workaround and only using addMimeTypeListener, it is working fine so far. thanks!
The intent filter is only required to launch the app when scanning a NFC tag.
What phone are you seeing this on? What version of Android is it running? Do you want until after device ready is called before processing NFC tags?
Ok, I don't need to launch the app when scanning a NFC tag. I only need to scan NFC tags within the app. I am using a Samsung Galaxy Young GT-S6310N. Android 4.1.2 (Jelly Bean).
@rogervinas I'm not seeing this on my phones with Android 4.4+. I think this is either a Samsung or Android 4.1 issue. For now stick with your workaround.
I experienced this issue too. I have an app that creates a listener on a tap of a button and it is not working on first scan, but it does on second (exactly how they described it), my workaround* is I created an ndefListener that does nothing upon scan on DEVICEREADY.
*I assumed that the nfc is only being initialized on first scan.
We have the same issue here. First scan after app start/wake fails.
Samsung Galaxy Young 2
@clintgh @obiwarn make sure you're waiting until device ready to do any Cordova api calls. I haven't been able to duplicate this, so I think it's an Android or Device specific issue. If you can create the simplest cordova app that duplicates the problem, I can try and duplicate with my hardware.
The device makes a scanning "success" sound (Not the sound it makes when it fails to read the tag). But the event seems to be not caught by any of the plugin events. (sorry for my english)
Oh and I use the plugin with Meteor.
@obiwarn can you get me a simple project that demonstrates this?
@obiwarn Look at https://github.com/chariotsolutions/phonegap-nfc/issues/144#issuecomment-99841539. @rogervinas has the same phone as you and was seeing a ndef-mime
event fired on the first tag scan. (This seems like a device specific issue.)
If that is the case, add a 2nd listener as a work around.
// your existing listener
nfc.addNdefListener(app.onNfc, success, failure);
// add a 2nd listener for the mime type
nfc.addMimeTypeListener('text/plain', app.onNfc, success, failure);
@don BTW: I had to guess the parameters for the callback, success and error functions. I am new to JS. Is there a better way to retrieve them or did you just miss it in the docs? (e.g. onNfc(result, error) , onError(error) )
addMimeTypeListener has the same lag on startup (i.e. only works 2nd time). It also causes my phone to open a system dialog ("Empty tag detected"). So it is not usable for me.
addTagDiscoveredListener works the first time. I just found out that it also retrieves the ndef id. So this seems like a solution.
I will try...
Yes. addTagDiscoveredListener works great.
@obiwarn This sounds like a device specific problem. Since you have a work around, I'm closing this issue. If you continue to have the problem, re-open the issue with sample code that demonstrates the issue.
The documentation could be better about the callback parameters. For now look at the sample projects for more details. (There's also a book.)
Hi @don I'm still experiencing the same issue. My first scan does not work, but the second time works.
Please see attached .txt file for the logs. log-nowork.txt <- first scan log-work.txt <- second scan
There is a major difference between the logs when it didn't work and the logs when it worked. One difference is in the log that didn't work (first scan), it is showing TECH_DISCOVERED but in the one that worked (second scan) it is showing NDEF_DISCOVERED
Found my solution buried inside the Pull Requests:
addNdefListener not calling callback on first attempt #218
See #217 Changes published in v1.0.1
We have an issue with our app where the first and only the first scan fails after the app is installed or waked up.
CORDOVA 3.5.0, tested on android 4.1 & 4.2.2
Code snip "Success" is fired OK when the app loads, scan event only fires on second scan.