Question

I want to create an app that stores a timestamp into the database when I scan my work-batch which contains an NFC tag. This will be done via an IntentService without starting an activity. After a second scan another timestamp will be stored into the database via the IntentService. No activity has to be started. A notification will be enough. The activity can be started manually by the user to see the info.

I have read that there are a lot of different tag technologies. But I like to make my app a bit more universal. So I don't know which kind of NFC tags my clients are going to use. I could listen for all the different tags and let the user pair a tag with a certain task.

This is fine unless there is one NFC app on the phone. But I have another app which uses NFC. And when I scan a tag Android shows me a selection dialog which app may handle the tag. But I don't want this every time I scan a tag. I want to use both apps so I dont select a default for the tags.

So the question is, How can I scan a tag and route it to the right app. So tag A will be handled by app A and tag B by app B without getting the selection box every time.

I was thinking what the best option should be or maybe somebody has a great idea how to solve this.

I have taught of a couple of different solutions:

  1. Use only writable NDEF tags and add a Android Application Record (AAR) to it. So it will launch the right application after scanning. (If there is no NFC app active in the foreground) this will mean that the user is restricted to a tag technology and needs to write it before using.

  2. Let the application listen for all NFC tags and if a tag is not paired to a task forward it to the system again so that other apps can handle it. (Don't know if this is possible)

  3. Write a app which listens for all NFC tags and let the user decide which tag will be send to which application. So when a new tag is received by the application it asks the user which app may handle the tag and stores the default for this specific tag [by ID or something] into a database. So the next time it will route the intent to the default application for this tag. (Or is there already something like this?)

Hopefully this question is a bit clear. Else I'll try to clarify it a bit more if you like ;-)

I really like to hear what you think about this. Or maybe you have some good suggestions? Please let me know.

Thanks in advance.

Was it helpful?

Solution

I've successfully use an application specific URL scheme for this. Let's assume your URL scheme is "kuiperstimestamp".

The tag then should contain a URL like:

kuiperstimestamp://ts/20130506T034536.293

You then create an intent filter for your service that includes a data element:

<intent-filter>
    <action android:name="android.nfc.action.TAG_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="kuiperstimestamp" />
</intent-filter>

Since the intent filter is rather specific, you don't get the app selection dialog (unless another app or service has the same specific intent filter which is unlikely).

This approach is less Android specific than using an AAR.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top