1

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.

1
  • 1
    The tech-list you used looked for a tag that supported ALL the formats you had listed. Listing them individually, like below, looks for the first tag OR the next tag OR the next tag OR... and so on. The above is a AND list. You can make groups of tags to more better identify what tags your application supports. Commented Sep 21, 2011 at 16:51

1 Answer 1

5

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:

<?xml version="1.0" encoding="utf-8"?> <resources> <tech-list> <tech>android.nfc.tech.IsoDep</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcA</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcB</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcF</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NfcV</tech> </tech-list> <tech-list> <tech>android.nfc.tech.Ndef</tech> </tech-list> <tech-list> <tech>android.nfc.tech.NdefFormatable</tech> </tech-list> <tech-list> <tech>android.nfc.tech.MifareClassic</tech> </tech-list> <tech-list> <tech>android.nfc.tech.MifareUltralight</tech> </tech-list> </resources> 
Sign up to request clarification or add additional context in comments.

3 Comments

hi, thanks for your reply, I have just changed the tech list. but it does not seem to help. but regardless whether the tech-discovery works, it should still work while I have the tag-discovery filter??
You can check the nfc-puzzle app I created for toying around with NFC for droidcon in Berlin.
I finally get it to work using your method with tech-discovery. but just a shame that tag-discovery still doesn't work, and I could not figure out why. anyway, thanks for your help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.