If you want your activity to launch (or the activity chooser to be shown) for tags that do not contain an NDEF message (or that do contain an NDEF message that is not filterable on Android), the android.nfc.action.TECH_DISCOVERED
intent is the way to go.
The android.nfc.action.TAG_DISCOVERED
intent filter is meant as a fall-back only. Thus it will only trigger if no other activity (not only your app) is registered for an intent filter that matches the tag.
The android.nfc.action.NDEF_DISCOVERED
intent filter will only trigger if the first NDEF record on the tag matches a given MIME type or if that record matches a given URI (including URI mapping for NFC Forum external types).
The android.nfc.action.TECH_DISCOVERED
intent filter should be used in the form:
<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_filter" />
No <data ... />
or <category ... />
tags should be added.
The resource file containing the tag list (xml/filter_nfc.xml
) must contain a vaild technology filter that matches your tag. Each <tech>...</tech>
entry specifies a tag technology that your intent filter will trigger upon. Multiple tag technology entries can be grouped to form either a logical AND or a logical OR. All <tech>
entries within one <tech-list>...</tech-list>
group are combined with logical AND. Multiple <tech-list>...</tech-list>
groups within the XML file are combined with logical OR. So if you want to trigger upon any NFC tag technology, your XML file would look like this:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" >
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcB</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcF</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcV</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcBarcode</tech>
</tech-list>
</resources>
Your XML file, on the other hand, would require a tag to have all tag technologies at the same time, which is impossible as some technologies are mutually exclusive to each other (e.g. a tag can't be detected as NfcA and NfcB at the same time).