android - Identifying NFC tag ID -


i trying identify unique identifier of nfc tag on android using following code:

@suppresslint("newapi") @override protected void oncreate(bundle savedinstancestate) {  super.oncreate(savedinstancestate);  setcontentview(r.layout.activity_main);  tag mytag = (tag) getintent().getparcelableextra(nfcadapter.extra_tag);  string nfcid = mytag.getid().tostring();     toast.maketext(getapplicationcontext(), "nfc id is: "+ nfcid, toast.length_short).show();       } 

unfortunately, when deploy app real device , scan nfc tag, app crash stating "unfortunately xyz has stop...". know getid() return byte array , have parse string. @ least expect code return values rather crashing app. ideas how fix it?

edited: logcat outputs:

w/dalvikvm(25548): threadid=1: thread exiting uncaught exception group=0x41b652a0) e/androidruntime(25548): fatal exception: main e/androidruntime(25548): java.lang.runtimeexception:  unable start activity componentinfo{com.xyz.nfcid/com.xyz.nfcid.mainactivity}:  @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) 

i'm pretty sure, tag null. should check action string first

string action = intent.getaction(); if (nfcadapter.action_ndef_discovered.equals(action)) {     //... } 

i've written complete tutorial, should you.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -