Android nfc to read card from samsung nexus -
i want read card samsung nexus phone android nfc api not provide enough options. i've tried using third party api names "open nfc" gives error of not supporting api. can provide me code read data card. have code read tag not read card. here link download open nfc api.
http://sourceforge.net/projects/open-nfc/files/open%20nfc%204.3%20beta%20%2810381%29/
any appreciated.
this code used. giving error of opennfc failing...
public class nfcone extends activity implements carddetectioneventhandler, readcompletioneventhandler,nfctagdetectioneventhandler{ cardlistenerregistry i=null; carddetectioneventhandler hand=null; nfcmanager nfcmngr = null; nfctagmanager mnfctagmanager=null; nfctagdetectioneventhandler taghand=null; readcompletioneventhandler readhand=null; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main1); system.out.println("oncreate"); try { nfcmngr.start(); i.registercardlistener(nfcpriority.maximum, hand); } catch(exception e) { } } protected void onresume() { // todo auto-generated method stub super.onresume(); system.out.println("onresume"); toast.maketext(this, "ndef reader starting ... ", toast.length_short) .show(); try{ if (mnfctagmanager != null) { mnfctagmanager.registertaglistener(nfcpriority.maximum, taghand); mnfctagmanager.registermessagereader(ndeftypenameformat.well_known, "u", nfcpriority.minimum, this); } } catch(exception e) { } } protected void onpause() { super.onpause(); system.out.println("onpause"); mnfctagmanager.unregistermessagereader(readhand); mnfctagmanager.unregistertaglistener(taghand); } protected void ondestroy() { super.ondestroy(); system.out.println("ondestroy"); i.unregistercardlistener(hand); try{ nfcmngr.stop(); } catch(exception e) { } } public void oncarddetected(connection connection) { system.out.println("oncarddetected"); //connectionproperty[] con = connection.getproperties(); } public void oncarddetectederror(nfcerrorcode what) { system.out.println("oncarddetectederror"); // todo auto-generated method stub } private void startbrowseron(string url) { system.out.println("startbrowseron"); startactivity(new intent(intent.action_view, uri.parse(url))); } public void onreaderror(nfcerrorcode what) { system.out.println("onreaderror"); } public void ontagread(ndefmessage message) { { system.out.println("ontagread"); if (message != null) { vector<ndefrecord> records = message.getrecords(); (int = 0; < records.size(); i++) { if (urirecord.isurirecord(records.elementat(i))) { urirecord uri; try { try { uri = new urirecord(records.elementat(i)); startbrowseron(uri.geturi().tostring()); } catch (nfcexception e) { // todo auto-generated catch block e.printstacktrace(); } } catch (urisyntaxexception e) { // todo auto-generated catch block e.printstacktrace(); toast.maketext(this, "urisyntaxexception! ", toast.length_short).show(); } break; }}}} } public void ontagdetected(nfctagconnection connection) { system.out.println("ontagdetected"); } public void ontagdetectederror(nfcerrorcode what) { system.out.println("ontagdetectederror"); } }
you need add opennfc library eclipse project.
right click on project , select properties
, go java build path|libraries
. click add external jars
, select opennfc library. finally, click on order , export
tab , make sure opennfc library checked export.
Comments
Post a Comment