MShekow
MShekow

Reputation: 1586

NFC detection different for Android 2.3.6 and 4.x

I discovered that when I put the Nexus S (running Android 2.3.6) next to a NFC tag which contains an NDEF message with an URI-record pointing to a web-site, this will cause (as expected) that the NFC activity chooser is shown (as I have several NFC reader apps installed, and I'm working on my own application that also intercepts detected NFC tags).

However, using the Galaxy Nexus (Android v4, Ice Cream Sandwich), the activity chooser does NOT appear. It will simply directly launch the browser. LogCat will show this:

D/NfcService(438): TAG: Tech [android.nfc.tech.MifareUltralight, android.nfc.tech.NfcA, android.nfc.tech.Ndef]
I/ActivityManager(196): START {flg=0x10008000 cmp=com.android.nfc3/com.android.nfc.NfcRootActivity (has extras)} from pid 438
I/ActivityManager(196): START {act=android.nfc.action.NDEF_DISCOVERED dat=http://www.someURL.com/someotherstuff cmp=com.google.android.browser/com.android.browser.BrowserActivity (has extras)} from pid 438

So this gives me two questions:

a) Android 2.3.6 and 4.x decide to behave differently, becaaaause...?

b) Even when I try to restrict my application to match only NFC tags that contain the www.someURL.com host, i.e. by putting

<data
    android:host="www.someURL.com"
    android:pathPattern="/*"
    android:scheme="http" />

into my 3 intent-filters (one for TAG_DISCOVERED, one for TECH_DISCOVERED, one for NDEF_DISCOVERED, I really tries to grab the NFC activity chooser's attention there..), the result won't change. It will just open the browser. ATM the only thing that works is Foreground-dispatching...

Any ideas?

Upvotes: 2

Views: 1149

Answers (2)

NFC guy
NFC guy

Reputation: 10228

You should probably use "android:pathPrefix" instead of "android:pathPattern". You are now matching 0 or more occurrences of "/"...

Upvotes: 2

Nils Pipenbrinck
Nils Pipenbrinck

Reputation: 86393

Your observation is correct:

a) Android 2.3.6 and 4.x decide to behave differently, becaaaause...?

Because with Android 4.0.x the behaviour for incoming NDEF-messages have been streamlined for a better user-experience. Android detects a few messages types and passes the data directly to the built-in applications.

I'm pretty sure this is done for URI-records which go to the browser and VCard messages that go to the contact application, but there could be other messages as well.

You can override this built-in behaviour by enabling foreground dispatch and having your application running with focus.

Upvotes: 2

Related Questions