4
votes

I am writing an application that is supposed to detect nfc tag and automatically be launched. I have succeeded in doing so by using TECH_DISCOVERED + filters but I think the better way to do it is by using NDEF_DISCOVERED. I have added the intent-filter to my manifest but it doesn't work. This is my manifest code for the TECH_DISCOVERED, that works:

    <intent-filter>    
    <action android:name="android.nfc.action.TECH_DISCOVERED"/>
    </intent-filter>
    <meta-data android:name="android.nfc.action.TECH_DISCOVERED"    
     android:resource="@xml/nfc_tech_filter" />

when I want to try the NDEF_DISCOVERED i try:

                <intent-filter>    
                <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="text/plain" />

for the tags, I use 'Mifare classic 1k' tags that was written as 'Smart Poster' using NFC TagInfo app from the market.

What am I doing wrong? or, what is another way to make my app be launched and not show the activity selection dialog?

Thanks, Eran.

1
Here is a sample application that will launch based on scanning a tag with a URL of commonsware.com/nfctest: github.com/commonsguy/cw-advandroid/tree/master/NFC/URLTagger -- I have not tried using android:mimeType as an NFC tag trigger.CommonsWare

1 Answers

4
votes

You are filtering for text/plain and not the URI of the smart poster. Android converts smart posters to URIs, then you have to filter for that URI. You can see the URI in logcat if you check for the intent that is started. For a URI like http://example.com/file, do something like this:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http"
            android:host="example.com"
            android:pathPrefix="/file" />
</intent-filter>

See the NFC dev guide for more information on how to parse NDEF messages. Please read the entire document to fully understand how to filter for the right intent: http://developer.android.com/guide/topics/nfc/nfc.html