问题描述
我已经在Activity的清单文件中声明了必需的Intent过滤器.
场景1:当我使用NFCDemo android示例应用程序->广泛投放nfc标签->进行测试时,我的应用程序会像其他nfc应用程序一样在选择器对话框中提示NFC标签信息&恩智浦标签信息.
场景2:刷过实际的NFC标签(卡片)-> NFC TagInfo之后,TagInfo应用程序会在选择器对话框中提示,但我的应用程序却没有.
我的要求->我的应用也应显示为NFC标签信息应用.更多信息->其为空卡!.
<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" />
仅当您的NFC标签包含与过滤器匹配的NDEF消息时,才会触发NDEF_DISCOVERED
意向过滤器.通常,您应该为特定的记录类型(例如,特定的MIME类型,特定的NFC论坛外部类型名称或特定的URI(前缀))指定过滤器.在某些设备上无法使用针对"*/*"的MIME类型过滤器.
通常不应在应用清单中使用TAG_DISCOVERED
意图过滤器.在当前的Android版本中,它主要与前台调度系统一起使用,如果没有其他活动针对任何标签发现事件进行注册,则作为后备.
TECH_DISCOVERED
意图过滤器将过滤support_nfc_techlist.xml文件中定义的那些标记技术.例如,如果您想检测任何标签,则可以使用如下过滤器:
<?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>
请注意,Android文档中的示例具有误导性.技术列表与逻辑 OR 组合,而一个技术列表中的技术条目与逻辑 AND 组合.因此,
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcB</tech>
</tech-list>
表示NfcA
OR NfcB
,而
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
</tech-list>
表示NfcA
AND 和NfcB
(不可能是NfcX
(X = {A,B,F,V}的组合)技术类型是互斥的. /p>
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 (e.g. 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.
这篇关于NFC标签未启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!