Wednesday 15 January 2014

Read NFC tag has content of Android Play app -



Read NFC tag has content of Android Play app -

i have tag has content of android play app. when phone approach it, it'll default open app page on android play store. want write app can read tag. modify androidmanifest.xml below:

<uses-permission android:name="android.permission.nfc" /> ...... <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.ndef_discovered" /> <category android:name="android.intent.category.default" /> <data android:host="ext" android:pathprefix="/android.com:pkg" android:scheme="vnd.android.nfc" /> </intent-filter> ......

i utilize tag app read tag, has content like:

ndef message external: urn:nfc:ext:android.com:pkg com.example.app

i think key point intent-filter. cannot lunch app when approach tag. no matter app in background or foreground. can help me? thanks.

i find answer. misunderstand meaning of foreground allow app beingness running @ foreground. has add together enableforegrounddispatch below:

private nfcadapter nfcadapter; private pendingintent mpendingintent; private intentfilter[] mfilters; private string[][] mtechlists; protected void oncreate(bundle savedinstancestate) nfcadapter = nfcadapter.getdefaultadapter(this); mpendingintent = pendingintent.getactivity(this, 0, new intent(this, getclass()).addflags(intent.flag_activity_single_top), 0); intentfilter ndefpkg = new intentfilter(nfcadapter.action_ndef_discovered); seek { ndefpkg.adddatascheme("vnd.android.nfc"); ndefpkg.adddataauthority("ext", null); ndefpkg.adddatapath("/android.com:pkg", 0); } grab (exception e) { e.printstacktrace(); } mfilters = new intentfilter[] {ndefpkg; mtechlists = new string[][] { new string[] { nfcf.class.getname() } }; } protected void onresume() { super.onresume(); nfcadapter.enableforegrounddispatch(this, mpendingintent, mfilters, mtechlists); } protected void onpause() { super.onpause(); nfcadapter.disableforegrounddispatch(this); }

android android-intent nfc

No comments:

Post a Comment