即使ACTION_NDEF_DISCOVERED操作也未发现NFC标签,即使它包含Ndef数据 [英] NFC tag is not discovered for ACTION_NDEF_DISCOVERED action even if it contains Ndef data

查看:200
本文介绍了即使ACTION_NDEF_DISCOVERED操作也未发现NFC标签,即使它包含Ndef数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Samsung S5读取2种不同的NFC标签.这两个标签都包含NDEF消息,第一个标签包含MIME类型记录作为其第一条记录,第二个标签包含替代载体记录(TNF = TNF_WELL_KNOWN,类型= RTD_ALTERNATIVE_CARRIER)作为其第一条记录.

I am trying to read 2 different NFC tags with a Samsung S5. Both tags contain an NDEF message, the first tag contains a MIME type record as its first record and the second tag contains an alternative carrier record (TNF = TNF_WELL_KNOWN, Type = RTD_ALTERNATIVE_CARRIER) as its first record.

当我使用 ACTION_TECH_DISCOVERED 意向通过前台调度读取标签时.对于第一个标签,技术列表列出了 NfcA MifareClassic Ndef .对于第二个标签,它列出了 NfcA Ndef .

When I read the tags through the foreground dispatch using ACTION_TECH_DISCOVERED intent. For the first tag, the tech-list lists NfcA, MifareClassic, and Ndef. For the second tag, it lists NfcA and Ndef.

当我尝试使用数据类型为"*/*"的 ACTION_NDEF_DISCOVERED 意向读取标签时,发现第一个标签很好,但是根本找不到第二个标签.

When I try to read the tag using ACTION_NDEF_DISCOVERED intent using the datatype "*/*" , the first tag is discovered fine, but the second tag is not discovered at all.

推荐答案

这里的问题是 NDEF_DISCOVERED 意向过滤器如何工作.使用 NDEF_DISCOVERED ,您可以监视某种数据类型(即MIME类型)或某种URI.在所有情况下,匹配都将应用于发现的标签的NDEF消息中的 first 记录.

The problem here is how the NDEF_DISCOVERED intent filter works. With the NDEF_DISCOVERED you can either watch for a certain datatype (i.e. a MIME type) or for a certain URI. In all cases, the matching will be applied for the first record in the NDEF message of a discovered tag.

通过数据类型匹配,您可以检测

  • 包含给定MIME媒体类型或
  • 的MIME类型记录
  • 带有映射到MIME类型"text/plain"的文本RTD记录(TNF_WELL_KNOWN + RTD_TEXT).

通过 URI匹配,您可以检测

  • URI RTD记录(TNF_WELL_KNOWN + RTD_URI),
  • 封装在Smart Poster RTD记录中的URI RTD记录,
  • 具有基于URI类型(TNF_ABSOLUTE_URI)的记录,或
  • NFC论坛外部类型记录(TNF_EXTERNAL).

这两种匹配类型是互斥的,因此您可以在一个意图过滤器中匹配数据类型或URI.

Both matching types are mutually exclusive, so you can either match for a datatype or for a URI in one intent filter.

对于第二个标签,NDEF意向分派系统不支持第一个记录的类型(TNF_WELL_KNOWN + RTD_ALTERNATIVE_CARRIER).因此,您不能将 NDEF_DISCOVERED 意向过滤器与该标记结合使用.

In the case of your second tag, the type of the first record (TNF_WELL_KNOWN + RTD_ALTERNATIVE_CARRIER) is not supported by the NDEF intent dispatch system. Hence, you cannot use the NDEF_DISCOVERED intent filter in combination with that tag.

匹配数据类型:

    清单中的
  • :

  • in the manifest:

<intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="some/mimetype" />
</intent-filter>

  • 用代码表示:

  • in code:

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    ndef.addDataType("some/mimetype");
    

  • 匹配网址:

      清单中的
    • :

    • in the manifest:

    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="http"
              android:host="somehost.example.com"
              android:pathPrefix="/somepath" />
    </intent-filter>
    

  • 用代码表示:

  • in code:

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    ndef.addDataScheme("http");
    ndef.addDataAuthority("somehost.example.com", null);
    ndef.addDataPath("/somepath", PatternMatcher.PATTERN_PREFIX);
    

  • 匹配NFC论坛外部类型:

    Matching for an NFC Forum External Type:

      清单中的
    • :

    • in the manifest:

    <intent-filter>
        <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="vnd.android.nfc"
              android:host="ext"
              android:pathPrefix="/com.example:sometype" />
    </intent-filter>
    

  • 用代码表示:

  • in code:

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    ndef.addDataScheme("vnd.android.nfc");
    ndef.addDataAuthority("ext", null);
    ndef.addDataPath("/com.example:sometype", PatternMatcher.PATTERN_PREFIX);
    

  • 这篇关于即使ACTION_NDEF_DISCOVERED操作也未发现NFC标签,即使它包含Ndef数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆