Android 安卓NFC:我能';t捕获空标记意图

Android 安卓NFC:我能';t捕获空标记意图,android,android-intent,nfc,Android,Android Intent,Nfc,感谢所有花时间阅读本文的人。对不起,我的英语不好。我学习,我保证 我正在开发一个使用NFC的Android应用程序。我有一个空标签的问题。当我阅读一个空标签时,我无法理解它的意图,它总是启动Android活动来阅读ta标签,并提到空标签。对于其他写有东西的标签,我没有问题 我搜索了一下,但没有找到好东西。我想我的问题在舱单上 因此,我当然要补充一点: <uses-permission android:name="android.permission.NFC" /> <uses

感谢所有花时间阅读本文的人。对不起,我的英语不好。我学习,我保证

我正在开发一个使用NFC的Android应用程序。我有一个空标签的问题。当我阅读一个空标签时,我无法理解它的意图,它总是启动Android活动来阅读ta标签,并提到空标签。对于其他写有东西的标签,我没有问题

我搜索了一下,但没有找到好东西。我想我的问题在舱单上

因此,我当然要补充一点:

<uses-permission android:name="android.permission.NFC" />

<uses-feature
    android:name="android.hardware.nfc"
    android:required="true" />

在我添加的活动中,第一次

<intent-filter>
            <action android:name="android.nfc.action.TECH_DISCOVERED" />

            <data android:mimeType="text/plain" />
 </intent-filter>

 <meta-data
            android:name="android.nfc.action.TECH_DISCOVERED"
            android:resource="@xml/nfc" />

xml/nfc.xml资源文件包含以下技术过滤器:

<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>

android.nfc.tech.IsoDep
android.nfc.tech.NfcA
android.nfc.tech.NfcB
android.nfc.tech.NfcF
android.nfc.tech.NfcV
android.nfc.tech.Ndef
android.nfc.tech.n可验证
android.nfc.tech.MifareClassic
android.nfc.tech.MifareUltralight
我在一些网站上读到,可能需要添加

<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.NDEF_DISCOVERED" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="*/*" />
</intent-filter>

所以我做了

但它不起作用


我知道我可能忘了什么。但是什么呢?

如果您希望为不包含NDEF消息(或确实包含不可在Android上过滤的NDEF消息)的标记启动活动(或显示活动选择器),则可以使用
Android.nfc.action.TECH

发现的
android.nfc.action.TAG_
intent过滤器只是一个后备过滤器。因此,只有在没有为与标记匹配的意图过滤器注册任何其他活动(不仅仅是您的应用程序)时,才会触发该事件

如果标记上的第一个NDEF记录与给定的MIME类型匹配,或者如果该记录与给定的URI匹配(包括nfc论坛外部类型的URI映射),则发现的
android.nfc.action.NDEF\u
intent过滤器将仅触发

发现的
android.nfc.action.TECH\u
intent过滤器应以以下形式使用:

<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" />


另一方面,您的XML文件需要一个标记同时拥有所有标记技术,这是不可能的,因为有些技术相互排斥(例如,标记不能同时被检测为NfcA和NfcB)。

好的,我解决了我的问题!这不是清单,而是java代码

在我第一次阅读有关nfc的教程时,我使用了部分代码。还有一些代码我没有适应你给我的建议

这是我代码的老部分

IntentFilter[] filters = new IntentFilter[1];
filters[0] = new IntentFilter();
filters[0].addAction(NfcAdapter.ACTION_TECH_DISCOVERED);
try {
    filters[0].addDataType(MIME_TEXT_PLAIN);
} catch (MalformedMimeTypeException e) {
    Log.e("App","Wrong mime")
}
adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
错误操作,mime类型。许多错误。。。我换成

final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
adapter.enableForegroundDispatch(activity, pendingIntent, null, null);
而且它工作得很好!我希望它能帮助像你这样的人通过你的解释帮助我


再次感谢您抽出时间

首先,
在技术过滤器中没有意义。其次,您的
nfc.xml
文件包含哪些条目?好的,我删除了mimeType。我的nfc.xml是:
android.nfc.tech.IsoDep android.nfc.tech.NfcA android.nfc.tech.NfcB android.nfc.tech.NfcV android.nfc.tech.Ndef android.nfc.tech.ndeformable android.nfc.tech.MifareClassic android.nfc.tech.MifareUltralight
Ok,谢谢你这么精确。我不知道。为了更好地使用技术列表,我更改了xml文件。这并没有解决我的问题。但它向我解释了很多事情:)
final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
adapter.enableForegroundDispatch(activity, pendingIntent, null, null);