I am trying to play around with my new android device and a nfc tag, where I have writen a very simple application to detect nfc tag. but however I tried, I could not get my device to start my activity when the tag is scanned. here is what I have:
the simplest Activity:
public class NFCIntentDispatch extends Activity{
private TextView mText;
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setContentView(R.layout.intent_dispatch);
mText = (TextView) findViewById(R.id.text);
}
}
and menifest.xml
<activity android:name="NFCIntentDispatch">
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
the nfc_tech_filter.xml under res/xml:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
the problem:
whenever the tag is scanned, my device(Nexus S 2.3.3) only launches the build in activity called “new tag collected”, but never shows a choose nor start my activity. any idea why this is happening, thanks for any help.
There is an error in the Android documentation regarding the tech-list, which took me quite a while to figure out in the first place.
You’ll have to open a list for each item, like this in order to get it working: