问题描述
我试图只是NFC的基本版本,但后来我发现,MIME类型区分大小写。我的应用程序包名有一个大写字母。
I'm attempting just the basic version of NFC, but then I discovered that MIME TYPE is case sensitive. The package name for my app has one capital letter.
包名: com.example.Main_Activity
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/com.example.Main_Activity"/>
</intent-filter>
有谁知道变通的办法?
Does anyone know a way around it?
感谢
推荐答案
MIME类型不区分大小写,按照RFC。然而,Android的意图过滤matiching是区分大小写的。为了克服这个问题,你应该的总是使用小写的MIME类型只。
MIME types are case-insensitive as per the RFC. However, Android's intent filter matiching is case-sensitive. In order to overcome this problem you should always use lower-case MIME types only.
具体的Android NFC API的MIME类型的记录辅助方法,MIME类型会被自动转换为只小写字母。所以调用方法 NdefRecord.createMime()
与混合案件类型名称将总是导致进入创建一个小写的唯一MIME类型的名字。例如。
Specifically with the Android NFC API's MIME type record helper methods, MIME types will automatically be converted to lower-case letters only. So calling the method NdefRecord.createMime()
with a mixed-case type name will always result into the creation of a lower-case only MIME type name. E.g.
NdefRecord r1 = NdefRecord.createMime("text/ThisIsMyMIMEType", ...);
NdefRecord r2 = NdefRecord.createMime("text/tHISiSmYmimetYPE", ...);
NdefRecord r3 = NdefRecord.createMime("text/THISISMYMIMETYPE", ...);
NdefRecord r4 = NdefRecord.createMime("text/thisismymimetype", ...);
都将导致进入创建相同的MIME类型记录类型:
will all result into the creation of the same MIME type record type:
+----------------------------------------------------------+
| MIME:text/thisismymimetype | ... |
+----------------------------------------------------------+
所以你的意图过滤器也需要进行全小写字母:
So your intent filter will also need to be all-lower-case letters:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/thisismymimetype" />
</intent-filter>
这篇关于NFC和MIME类型区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!