David Kuridža
David Kuridža

Reputation: 7197

NFC listener trigger based on tag

I am doing a research on NFC and its use, I've started with a simple proof of concept by creating an NFC application for Android. When tag is scanned, it sends REST request with tag's ID to see whether it is registered with the service, and if is, content is downloaded and played on the phone.

The problem is tags' ID are sequential, the requirement is to have some unique random information stored to avoid possible complications and security issues. The question is, what should the data be? Is there some standard on the subject?

The idea is to store x,y where x is trigger identifier and y is a random unique number. Would this work? Can custom activity be started based on x value?

Any help and references are appreciated. There will be cake.

Upvotes: 1

Views: 5076

Answers (3)

Anup Warnulkar
Anup Warnulkar

Reputation: 783

I used the FakeTagsActivity to load NDEF message into NFCAdapter. I am passing the URI/text message through an intent. But unable to launch the TagViewer activity with following intent filter.

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

Upvotes: 0

ryan hickman
ryan hickman

Reputation: 71

I have a plugin I developed for NFC (phonegap) and I simply use:

<data android:mimeType="text/pg" />

And it works like a charm.

Upvotes: 1

Dave MacLean
Dave MacLean

Reputation: 5173

You definitely want to check out this page, which describes the latest dispatch process for a newly-detected tag: http://developer.android.com/reference/android/nfc/Tag.html. It now makes a difference if your tag-detecting app is expected to be running at the time the tag is scanned. If it's in the foreground, you can be sure that your activity is going to get first crack at a scanned tag, whatever tag is detected. If your app is not already running but is installed on the device, then the intent filter(s) in your AndroidManifest.xml will dictate whether or not your app has a chance at being notified of the detected tag. Previously, all tag data was put into the extras of the intent that was sent out. But in 2.3.3, if there is a URI in the tag's first NDEF record, and the tag is URI or SmartPoster, that URI gets put into the intent's data field, which will be used when matching against intent filters. If the tag is a MIME_TYPE tag, the mime type is put into the intent's type field. Therefore, if you use a custom URI or custom MIME type that your app is looking for, you should always get notified of your tags (unless another app is in the foreground and has requested all tags).

Upvotes: 2

Related Questions