Skip to content
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

ICS - NFC tag opens app but does not trigger onNFC event #22

Closed
dejanmauer opened this issue Jun 6, 2012 · 7 comments
Closed

ICS - NFC tag opens app but does not trigger onNFC event #22

dejanmauer opened this issue Jun 6, 2012 · 7 comments

Comments

@dejanmauer
Copy link

First of all this is a great plugin!

One issue that I have (Samsung Galaxy Nexus) is that I wrote app that reads NFC tag. It works just fine when I first start app and put the tag to the phone.

Since I would like to make user experience better, I added Intent to manifest file which actually opens my application when I put NFC tag to my phone. But it seems that it does not trigger onNFC event.

Am I doing something wrong or is anyone experiencing the same issue?

@don
Copy link
Member

don commented Jun 6, 2012

I can't duplicate this. I'm using phonegap-nfc-0.4.0, cordova-1.6.1, sdk-version 15, samsung galaxy nexus (GSM).

Can you send me some info about your setup so I can duplicate this? Can you post or email me the intent from your manifest and the log file from adb logcat?

Android Manifest

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <data android:mimeType="text/pg" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

adb logcat

D/CordovaLog(10781): Viewport argument value "320;" for key "width" was truncated to its numeric prefix.
D/CordovaLog(10781): file:///android_asset/www/index.html: Line 4 : Viewport argument value "320;" for key "width" was truncated to its numeric prefix.
V/Web Console(10781): Viewport argument value "320;" for key "width" was truncated to its numeric prefix. at file:///android_asset/www/index.html:4
D/SoftKeyboardDetect(10781): Ignore this event
I/ActivityManager(  192): Displayed com.chariotsolutions.nfc.demo.reader/.ReaderDemo: +215ms (total +224ms)
D/OpenGLRenderer(  423): Flushing caches (mode 0)
D/NfcPlugin(10781): execute init
D/NfcPlugin(10781): Enabling plugin Intent { act=android.nfc.action.NDEF_DISCOVERED typ=text/pg cmp=com.chariotsolutions.nfc.demo.reader/.ReaderDemo (has extras) }
D/NfcPlugin(10781): parseMessage Intent { act=android.nfc.action.NDEF_DISCOVERED typ=text/pg cmp=com.chariotsolutions.nfc.demo.reader/.ReaderDemo (has extras) }
D/NfcPlugin(10781): action android.nfc.action.NDEF_DISCOVERED
D/CordovaLog(10781): Error: Status=2 Message=Class not found
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js: Line 908 : Error: Status=2 Message=Class not found
I/Web Console(10781): Error: Status=2 Message=Class not found at file:///android_asset/www/cordova-1.6.1.js:908
D/CordovaLog(10781): Error initializing Network Connection: Class not found
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js: Line 4634 : Error initializing Network Connection: Class not found
I/Web Console(10781): Error initializing Network Connection: Class not found at file:///android_asset/www/cordova-1.6.1.js:4634
V/NfcPlugin(10781): var e = document.createEvent('Events');
V/NfcPlugin(10781): e.initEvent('ndef-mime');
V/NfcPlugin(10781): e.tag = {"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC Forum Type 2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]};
V/NfcPlugin(10781): document.dispatchEvent(e);
D/NfcPlugin(10781): execute registerMimeType
D/chromium(10781): Unknown chromium error: -400
D/CordovaLog(10781): JSCallback Error: Request failed.
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js: Line 3557 : JSCallback Error: Request failed.
I/Web Console(10781): JSCallback Error: Request failed. at file:///android_asset/www/cordova-1.6.1.js:3557
D/CordovaLog(10781): {"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC Forum Type 2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]}
D/CordovaLog(10781): file:///android_asset/www/main.js: Line 59 : {"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC Forum Type 2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]}
I/Web Console(10781): {"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC Forum Type 2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]} at file:///android_asset/www/main.js:59
D/CordovaLog(10781): Initialized the NfcPlugin
D/CordovaLog(10781): file:///android_asset/www/phonegap-nfc-0.4.0.js: Line 7 : Initialized the NfcPlugin
I/Web Console(10781): Initialized the NfcPlugin at file:///android_asset/www/phonegap-nfc-0.4.0.js:7
D/CordovaLog(10781): Listening for NDEF tags.
D/CordovaLog(10781): file:///android_asset/www/main.js: Line 123 : Listening for NDEF tags.
I/Web Console(10781): Listening for NDEF tags. at file:///android_asset/www/main.js:123

@dejanmauer
Copy link
Author

Hi,

I am useing phonegap-nfc-0.4.0 and PhoneGap 1.7.0 (I have tried also on
PhoneGap 1.6.1, but later upgraded project because of the issue).
My phone is Samsung Galaxy Nexus (GSM) and the project is build upon
sdk-version 14 (since my phone works only with v.14).

I have attached project folder where you can find manifest file.

CatLog from my phone is also attached. First I have put NFC card to the
phone and application showed up, but did not triger onNFC event, so no card
information were displayed. I removed the card and left application open.
After a second I have put the same card to the phone again and the
information from the card was displayed.

I hope this will help you evaluate issue.

Thank you for your quick support. I really like your work!

Best regards,
Dejan

On Wed, Jun 6, 2012 at 3:59 PM, Don Coleman <
reply@reply.github.com

wrote:

I can't duplicate this. I'm using phonegap-nfc-0.4.0, cordova-1.6.1,
sdk-version 15, samsung galaxy nexus (GSM).

Can you send me some info about your setup so I can duplicate this? Can
you post or email me the intent from your manifest and the log file from
adb logcat?

Android Manifest

       <intent-filter>
           <action android:name="android.nfc.action.NDEF_DISCOVERED" />
           <data android:mimeType="text/pg" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>

adb logcat

   D/CordovaLog(10781): Viewport argument value "320;" for key "width"

was truncated to its numeric prefix.
D/CordovaLog(10781): file:///android_asset/www/index.html: Line 4 :
Viewport argument value "320;" for key "width" was truncated to its numeric
prefix.
V/Web Console(10781): Viewport argument value "320;" for key
"width" was truncated to its numeric prefix. at
file:///android_asset/www/index.html:4
D/SoftKeyboardDetect(10781): Ignore this event
I/ActivityManager( 192): Displayed
com.chariotsolutions.nfc.demo.reader/.ReaderDemo: +215ms (total +224ms)
D/OpenGLRenderer( 423): Flushing caches (mode 0)
D/NfcPlugin(10781): execute init
D/NfcPlugin(10781): Enabling plugin Intent {
act=android.nfc.action.NDEF_DISCOVERED typ=text/pg
cmp=com.chariotsolutions.nfc.demo.reader/.ReaderDemo (has extras) }
D/NfcPlugin(10781): parseMessage Intent {
act=android.nfc.action.NDEF_DISCOVERED typ=text/pg
cmp=com.chariotsolutions.nfc.demo.reader/.ReaderDemo (has extras) }
D/NfcPlugin(10781): action android.nfc.action.NDEF_DISCOVERED
D/CordovaLog(10781): Error: Status=2 Message=Class not found
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js:
Line 908 : Error: Status=2 Message=Class not found
I/Web Console(10781): Error: Status=2 Message=Class not found at
file:///android_asset/www/cordova-1.6.1.js:908
D/CordovaLog(10781): Error initializing Network Connection: Class
not found
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js:
Line 4634 : Error initializing Network Connection: Class not found
I/Web Console(10781): Error initializing Network Connection: Class
not found at file:///android_asset/www/cordova-1.6.1.js:4634
V/NfcPlugin(10781): var e = document.createEvent('Events');
V/NfcPlugin(10781): e.initEvent('ndef-mime');
V/NfcPlugin(10781): e.tag =
{"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC
Forum Type
2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]};
V/NfcPlugin(10781): document.dispatchEvent(e);
D/NfcPlugin(10781): execute registerMimeType
D/chromium(10781): Unknown chromium error: -400
D/CordovaLog(10781): JSCallback Error: Request failed.
D/CordovaLog(10781): file:///android_asset/www/cordova-1.6.1.js:
Line 3557 : JSCallback Error: Request failed.
I/Web Console(10781): JSCallback Error: Request failed. at
file:///android_asset/www/cordova-1.6.1.js:3557
D/CordovaLog(10781):
{"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC
Forum Type
2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]}
D/CordovaLog(10781): file:///android_asset/www/main.js: Line 59 :
{"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC
Forum Type
2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]}
I/Web Console(10781):
{"isWritable":true,"id":[4,-53,-111,26,67,40,-128],"techTypes":["android.nfc.tech.MifareUltralight","android.nfc.tech.NfcA","android.nfc.tech.Ndef"],"type":"NFC
Forum Type
2","canMakeReadOnly":true,"maxSize":137,"ndefMessage":[{"id":[],"type":[116,101,120,116,47,112,103],"payload":[72,101,108,108,111,32,80,104,111,110,101,71,97,112],"tnf":2}]}
at file:///android_asset/www/main.js:59
D/CordovaLog(10781): Initialized the NfcPlugin
D/CordovaLog(10781):
file:///android_asset/www/phonegap-nfc-0.4.0.js: Line 7 : Initialized the
NfcPlugin
I/Web Console(10781): Initialized the NfcPlugin at
file:///android_asset/www/phonegap-nfc-0.4.0.js:7
D/CordovaLog(10781): Listening for NDEF tags.
D/CordovaLog(10781): file:///android_asset/www/main.js: Line 123 :
Listening for NDEF tags.
I/Web Console(10781): Listening for NDEF tags. at
file:///android_asset/www/main.js:123


Reply to this email directly or view it on GitHub:

#22 (comment)

@don
Copy link
Member

don commented Jun 6, 2012

Dejan - It looks like the attachments didn't make it. Can you mail them to don at chariotsolutions dot com?

@dejanmauer
Copy link
Author

Hi,

I put it on Dropbox : https://dl.dropbox.com/u/72440/nfc.zip

regards,
Dejan

On Wed, Jun 6, 2012 at 4:59 PM, Don Coleman <
reply@reply.github.com

wrote:

Dejan - It looks like the attachments didn't make it. Can you mail them
to don at chariotsolutions dot com?


Reply to this email directly or view it on GitHub:

#22 (comment)

@don
Copy link
Member

don commented Jun 6, 2012

Got it. I'll take a look later today.

On Wed, Jun 6, 2012 at 11:02 AM, dejanmauer
reply@reply.github.com
wrote:

Hi,

I put it on Dropbox : https://dl.dropbox.com/u/72440/nfc.zip

regards,
Dejan

On Wed, Jun 6, 2012 at 4:59 PM, Don Coleman <
reply@reply.github.com

wrote:

Dejan - It looks like the attachments didn't make it.  Can you mail them
to don at chariotsolutions dot com?


Reply to this email directly or view it on GitHub:

#22 (comment)


Reply to this email directly or view it on GitHub:
#22 (comment)

@don
Copy link
Member

don commented Jun 6, 2012

Here's what's happening:

Your intent filter in the manifest has a mime-type, so an ndef-mime event is begin dispatched from phonegap-nfc.

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <data android:mimeType="text/plain" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Your code is listening for ndef events, so it ignores the ndef-mime event that launches the app.

nfc.addNdefListener(onNFC, win, fail);

You can use the same onNFC listener to handle ndef-mime events.

nfc.addMimeTypeListener("text/plain", onNFC, win, fail);

You can keep both the ndefListener and the mimeTypeListener, however once the mimeTypeListener is added you won't see ndef events for plain text tags. Android uses the most specific intent filter when scanning. Also it appears that android treats tags that are TNF WELL_KNOWN RTD type TEXT the same as TNF MIME_MEDIA type "text/plain".

You could switch your code to only have the mimeTypeListener if you don't want it to scan other ndef tags.

Are you creating the NFC tags? You might consider using your own unique mime type "text/centsi", so that your application scans your tags and other applications ignore your tags.

@dejanmauer
Copy link
Author

Thank you very much for the explanation and help me solve my issue.

Have a nice day,
Dejan

On Wed, Jun 6, 2012 at 9:16 PM, Don Coleman <
reply@reply.github.com

wrote:

Here's what's happening:

Your intent filter in the manifest has a mime-type, so an ndef-mime
event is begin dispatched from phonegap-nfc.

   <intent-filter>
       <action android:name="android.nfc.action.NDEF_DISCOVERED" />
        <data android:mimeType="text/plain" />
        <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>

Your code is listening for ndef events, so it ignores the ndef-mime
event that launches the app.

   nfc.addNdefListener(onNFC, win, fail);

You can use the same onNFC listener to handle ndef-mime events.

   nfc.addMimeTypeListener("text/plain", onNFC, win, fail);

You can keep both the ndefListener and the mimeTypeListener, however
once the mimeTypeListener is added you won't see ndef events for plain
text tags. Android uses the most specific intent filter when scanning.
Also it appears that android treats tags that are TNF WELL_KNOWN RTD type
TEXT the same as TNF MIME_MEDIA type "text/plain".

You could switch your code to only have the mimeTypeListener if you don't
want it to scan other ndef tags.

Are you creating the NFC tags? You might consider using your own unique
mime type "text/centsi", so that your application scans your tags and other
applications ignore your tags.


Reply to this email directly or view it on GitHub:

#22 (comment)

@don don closed this as completed Jul 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants