android - NFC P2P tag intercept -


i building android app using eclipse , android sdk. implement nfc p2p function in app in sense when place 2 phones back, both send string , receive string automatically. of course happen in separate activity. have managed send custom tag (string) have been unable intercept , use afterwards in app code. how can this?

this have far:

public class mainactivity extends activity {  public nfcadapter madapter; pendingintent mpendingintent;   @override  protected void oncreate(bundle savedinstancestate) {      super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_main);        madapter = nfcadapter.getdefaultadapter(this);       ndefrecord rec = ndefrecord.createuri("www.stackoverflow.com");       ndefmessage ndef = new ndefmessage(rec);       madapter.setndefpushmessage(ndef, this);  } 

i have spent lot of time trying find , understand solutions intercept tag. unsuccessfully.

thank help.

you can use foreground dispatch system receive ndef message within activity:

  1. in onresume():

    pendingintent pendingintent = pendingintent.getactivity(this, 0, new intent(this, getclass()).addflags(intent.flag_activity_single_top), 0); nfcadapter nfcadapter = nfcadapter.getdefaultadapter(this); nfcadapter.enableforegrounddispatch(this, pendingintent, null, null); 
  2. do upon receiving intent:

    public void onnewintent(intent intent) {     ... } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -