java - New Tag Collected Dialog appears when app tries to read NFC payload from the tag -
i'm trying understand nfc concept creating sample android app. when try read payload tag, dialog appears title new tag collected , tag payload in it. not want dialog appear. want print out toast instead. can me?
public class mainactivity extends appcompatactivity { nfcadapter nfcadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); nfcadapter = nfcadapter.getdefaultadapter(this); if(nfcadapter!=null && nfcadapter.isenabled()) { toast.maketext(this, "nfc detected",toast.length_long).show(); } else { finish(); toast.maketext(this, "nfc not detected",toast.length_long).show(); } } @override protected void onnewintent(intent intent) { toast.maketext(this,"new nfc tag found!",toast.length_long).show(); parcelable[] parcelables = intent.getparcelablearrayextra(nfcadapter.extra_ndef_messages); readtextmessage((ndefmessage)parcelables[0]); super.onnewintent(intent); } @override protected void onresume() { super.onresume(); intent intent = getintent(); string action = intent.getaction(); if (nfcadapter.action_tag_discovered.equals(action)) { toast.maketext(this, "onresume() - action_tag_discovered", toast.length_short).show(); tag tag = intent.getparcelableextra(nfcadapter.extra_tag); if(tag == null){ toast.maketext(this,"null",toast.length_long); }else{ string taginfo = tag.tostring(); toast.maketext(this,taginfo,toast.length_long); } }else{ toast.maketext(this, "onresume() : " + action, toast.length_short).show(); } } @override protected void onpause() { nfcadapter.disableforegrounddispatch(this); super.onpause(); }
}
Comments
Post a Comment