Dar*_*oki 2 android nfc intentfilter mifare ndef
我正在尝试使用三星 S5 读取 2 个不同的 NFC 标签。两个标签都包含一条 NDEF 消息,第一个标签包含 MIME 类型记录作为其第一条记录,第二个标签包含替代载体记录(TNF = TNF_WELL_KNOWN,类型 = RTD_ALTERNATIVE_CARRIER)作为其第一条记录。
当我使用ACTION_TECH_DISCOVERED意图通过前台调度读取标签时。对于第一个标签,以科技股名单列表NfcA,MifareClassic和Ndef。对于第二个标签,它列出NfcA和Ndef。
当我尝试ACTION_NDEF_DISCOVERED使用数据类型 "*/*"使用意图读取标签时,发现第一个标签很好,但根本没有发现第二个标签。
这里的问题是NDEF_DISCOVERED意图过滤器是如何工作的。使用NDEF_DISCOVERED可以查看特定数据类型(即 MIME 类型)或特定 URI。在所有情况下,匹配将应用于已发现标签的 NDEF 消息中的第一条记录。
通过数据类型匹配,您可以检测
使用URI 匹配,您可以检测
两种匹配类型是互斥的,因此您可以在一个意图过滤器中匹配数据类型或 URI。
对于您的第二个标签,NDEF 意图调度系统不支持第一条记录的类型 (TNF_WELL_KNOWN + RTD_ALTERNATIVE_CARRIER)。因此,您不能使用NDEF_DISCOVERED意图过滤器与该标签结合使用。
匹配数据类型:
在清单中:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="some/mimetype" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)在代码中:
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
ndef.addDataType("some/mimetype");
Run Code Online (Sandbox Code Playgroud)匹配一个网址:
在清单中:
<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>
Run Code Online (Sandbox Code Playgroud)在代码中:
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
ndef.addDataScheme("http");
ndef.addDataAuthority("somehost.example.com", null);
ndef.addDataPath("/somepath", PatternMatcher.PATTERN_PREFIX);
Run Code Online (Sandbox Code Playgroud)匹配NFC论坛外部类型:
在清单中:
<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>
Run Code Online (Sandbox Code Playgroud)在代码中:
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);
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
2783 次 |
| 最近记录: |