简体   繁体   中英

Activity is not launched by NFC Tag

I've declared required intent filters, in manifest file for Activity.

Scenario #1: when I tested with NFCDemo android sample app -> broad cast nfc tag -> that time my app is prompted in chooser dialog like other nfc apps NFC Tag Info & NXP Tag Info.

Scenario #2: After swiping real NFC Tag(card) -> NFC TagInfo, TagInfo apps are prompted in chooser dialog, but my app didn't.

my requirement -> My app also should be displayed like NFC Tag info app. more info -> its an empty card!.

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
    <action android:name="android.nfc.action.TAG_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
    <action android:name="android.nfc.action.TECH_DISCOVERED" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>    
<meta-data
    android:name="android.nfc.action.TECH_DISCOVERED"
    android:resource="@xml/supporting_nfc_techlist" />

The NDEF_DISCOVERED intent filter will only be triggered if your NFC tag contains an NDEF message that matches the filter. You should typically specify a filter for a specific record type (eg for a specific MIME type, for a specific NFC Forum external type name, or for a specific URI(-prefix)). Using a MIME type filter for "*/*" will not work on some devices.

The TAG_DISCOVERED intent filter should normally not be used in the app manifest. On current Android versions it is primarily used with the foreground dispatch system and as a fall back if no other activity is registered for any tag discovery events.

The TECH_DISCOVERED intent filter will filter for those tag technologies that are defined in the supporting_nfc_techlist.xml file. For instance, if you want to detect any tag, you could use a filter like this:

<?xml version="1.0" encoding="UTF-8"?>
<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.IsoDep</tech>
  </tech-list>
  <tech-list>
    <tech>android.nfc.tech.MifareClassic</tech>
  </tech-list>
  <tech-list>
    <tech>android.nfc.tech.MifareUltralight</tech>
  </tech-list>
  <tech-list>
    <tech>android.nfc.tech.NdefFormatable</tech>
  </tech-list>
  <tech-list>
    <tech>android.nfc.tech.Ndef</tech>
  </tech-list>
  <tech-list>
    <tech>android.nfc.tech.NfcBarcode</tech>
  </tech-list>
</resources>

Note that the example in the Android documentation is misleading. Tech-lists are combined with logical OR while tech-entries within one tech-list are combined with logical AND . Thus,

<tech-list>
  <tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
  <tech>android.nfc.tech.NfcB</tech>
</tech-list>

means NfcA OR NfcB , while

<tech-list>
  <tech>android.nfc.tech.NfcA</tech>
  <tech>android.nfc.tech.NfcB</tech>
</tech-list>

means NfcA AND NfcB (a combination that is not possible as NfcX (with X = {A, B, F, V}) technology types are mutually exclusive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM