mic*_*ele 5 android nfc intentfilter android-intent mifare
我正在编写一个适用于NFC和MIFARE CARD的应用程序.
当我的NFC设备检测到卡时,它会显示可以使用NFC的应用程序列表,但我的应用程序未被提及.
我的android清单文件中缺少什么?
<uses-permission android:name="android.permission.NFC" />
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<uses-feature
android:name="android.hardware.nfc"
android:required="true" />
<application
android:icon="@drawable/ic_launcher" android:allowBackup="true"
android:label="@string/app_name" android:theme="@style/AppTheme" >
<activity android:uiOptions="splitActionBarWhenNarrow"
android:name="it.namespace.app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/tech_filter" />
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
这是我的tech_filter文件xml:
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2" >
<tech-list>
<tech>
android.nfc.tech.MifareClassic
</tech>
</tech-list>
</resources>
Run Code Online (Sandbox Code Playgroud)
这里的图像显示我的应用程序不在列表中:

小智 14
我有同样的问题,我根据android doc http://developer.android.com/guide/topics/connectivity/nfc/nfc.html#tech-disc中的这句话修复了它
"如果您的活动过滤了ACTION_TECH_DISCOVERED意图,则必须创建一个XML资源文件,该文件指定您的活动在技术列表集中支持的技术.如果技术列表集是技术的子集,则您的活动被视为匹配标记支持,您可以通过调用getTechList()获得.
例如,如果扫描的标记支持MifareClassic,NdefFormatable和NfcA,则您的技术列表集必须指定所有三种,两种或其中一种技术(而不是其他任何技术),以便匹配您的活动.
您的nfc_tech_list需要定义当前标记支持的技术子集.
- 像这样定义你的清单:
<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/nfc_tech_list" />
</activity>
Run Code Online (Sandbox Code Playgroud)
- 像这样定义xml nfc_check_list:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.Ndef</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.Ndef</tech>
</tech-list>
</resources>
Run Code Online (Sandbox Code Playgroud)
这将完美地工作.
您是否创建了技术列表资源?
来自:http ://developer.android.com/guide/topics/connectivity/nfc/nfc.html#tech-disc
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
Run Code Online (Sandbox Code Playgroud)
如果您过滤 android.nfc.action.NDEF_DISCOVERED 而不是 android.nfc.action.TECH_DISCOVERED,则不需要技术列表。
您当前所拥有的内容应该会进入 android.nfc.action.TAG_DISCOVERED(请参阅引用页面上的流程图)。
很可能正在生成应用程序列表,因为所有这些应用程序都处理 NDEF_DISCOVERED。NFC 调度程序的一般意图是创建一个 Intent 并将其传递给第一个匹配的应用程序。仅当多个应用程序与过滤器匹配时才会显示应用程序选择器。从流程图来看,当可以调度匹配操作时,匹配就会停止。
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16544 次 |
| 最近记录: |