Reputation: 29925
Here is my intent-filter code...
<activity android:name="IntentReceiver">
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="http"
android:host="mytix.com"
android:pathPattern="/" />
<data
android:scheme="http"
android:host="www.mytix.com"
android:pathPattern="/" />
</intent-filter>
</activity>
What I want to do is intercept any NFC tags which have a url data type and the url is pointing to http://mytix.com (or http://www.mytix.com).
However the above code doesn't seem to work. Instead my NFC tags just open the browser and go the url in question (which is the right url! :) I've checked).
How do I intercept the intent? What I want to end up with is a tag that will take users to the mobile website if they don't have the app, but if they have the app installed it will take them straight to the app. I believe I am on the right lines, but the code above doesn't work for some reason.
I'm installing the app by building straight to the phone from Eclipse btw - does this make a difference?
Thanks
Tom
Upvotes: 0
Views: 550
Reputation: 1006704
What I want to do is intercept any NFC tags which have a url data type and the url is pointing to http://mytix.com (or http://www.mytix.com).
Try NDEF_DISCOVERED
, not TAG_DISCOVERED
. Android will only support direct launches like this for NDEF-formatted NFC tags. If your NFC tag is using something else, you can't use the <intent-filter>
AFAIK, but rather would have to parse the data out yourself.
Here is a book sample project that demonstrates writing a URL to an NDEF-formatted tag (triggered via the Share Page option in a browser app) and responding to NDEF-formatted tags with a specific URL written to them.
Upvotes: 1