Android 即使NFC标记包含NDEF数据,也不会为已发现的操作查找NFC标记
我试着用三星S5读取2个不同的NFC标签。两个标记都包含NDEF消息,第一个标记包含一个MIME类型记录作为其第一个记录,第二个标记包含一个备用载波记录(TNF=TNF\u众所周知,type=RTD\u备用载波)作为其第一个记录 当我使用Android 即使NFC标记包含NDEF数据,也不会为已发现的操作查找NFC标记,android,nfc,intentfilter,mifare,ndef,Android,Nfc,Intentfilter,Mifare,Ndef,我试着用三星S5读取2个不同的NFC标签。两个标记都包含NDEF消息,第一个标记包含一个MIME类型记录作为其第一个记录,第二个标记包含一个备用载波记录(TNF=TNF\u众所周知,type=RTD\u备用载波)作为其第一个记录 当我使用ACTION\u TECH\u通过前台调度读取标签时,我发现了intent。对于第一个标签,技术列表列出了NfcA、MifareClassic和Ndef。对于第二个标记,它列出了NfcA和Ndef 当我尝试使用数据类型“*/*”使用ACTION\u NDEF\u
ACTION\u TECH\u通过前台调度读取标签时,我发现了intent。对于第一个标签,技术列表列出了NfcA
、MifareClassic
和Ndef
。对于第二个标记,它列出了NfcA
和Ndef
当我尝试使用数据类型“*/*”使用ACTION\u NDEF\u DISCOVERED
intent读取标记时,第一个标记被很好地发现,但第二个标记根本没有被发现。这里的问题是NDEF\u DISCOVERED
intent过滤器如何工作。使用NDEF_DISCOVERED
可以查看特定的数据类型(即MIME类型)或特定的URI。在所有情况下,匹配将应用于已发现标记的NDEF消息中的第一条记录
使用数据类型匹配,您可以检测
- 包含给定MIME媒体类型的MIME类型记录,或
- 文本RTD记录(TNF_WELL_KNOWN+RTD_Text),映射到MIME类型“Text/plain”
使用URI匹配,您可以检测
- URI RTD记录(众所周知+RTD URI)
- 封装在Smart Poster RTD记录中的URI RTD记录
- 具有基于URI的类型(绝对URI)的记录,或
- NFC论坛外部类型记录(TNF_外部)
两种匹配类型都是互斥的,因此您可以在一个意图过滤器中匹配数据类型或URI
对于您的第二个标签,NDEF意向分派系统不支持第一条记录的类型(TNF_众所周知+RTD_替代_载体)。因此,您不能将NDEF\u DISCOVERED
intent过滤器与该标记结合使用
例子
数据类型的匹配:
- 在舱单中:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="some/mimetype" />
</intent-filter>
<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>
<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>
匹配URL:
- 在舱单中:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="some/mimetype" />
</intent-filter>
<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>
<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>
NFC论坛外部类型的匹配:
- 在舱单中:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="some/mimetype" />
</intent-filter>
<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>
<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>
两个标签上存储了什么数据?只是以Ndef格式写入的简单测试数据。好的,澄清我的问题:在这些标签上的Ndef消息中,第一个Ndef记录的数据类型是什么?在第一个标签TNFType=TNF\u MIME\u媒体和第二个标签TNFType=TNF\u众所周知,RTDType=RTD\u备用载体中