【发布时间】:2016-11-23 14:47:55
【问题描述】:
嘿,StackOverflowers...
我正在支持具有 NFC 读取功能的应用程序,它需要通过扫描 NFC 标签来打开应用程序。它适用于 4.3 和所有 4.X 版本 android.nfc.action.NDEF_DISCOVERED intent-filter。
所以网址是这样的:http://www.example.com/nfc/NFC00000001
我已经阅读了几乎所有关于 NFC 意图过滤器的相关答案。
如果活动已打开,我可以通过代码获取 NFC 标签,但这不是我需要的。
NFC 阅读器应用显示我的标签是
NXP MIFARE Ultralight(Ultralight C)-NTAG213
而且它支持
NfcA、MifareUltralight、Ndef
不适用于 Android 6(Nexus 4)、Android 6(OnePlus 3) 和 Andorid 7.1.1(Nexus 6P)。我没有其他 Android 6 和 7 设备,因此无法在 Android 5 上进行测试。
我尝试使用和不使用android.nfc.action.TECH_DISCOVERED
我尝试了几乎所有可能的选项,这是我最后的方法,但也不起作用(应用程序未启动)。
<activity
android:name=".activities.QRActivity"
android:launchMode="singleInstance"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:pathPattern="/nfc/..*"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:pathPattern="/nfc/..*"
android:scheme="http" />
</intent-filter>
<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPattern="/nfc/..*"
android:scheme="http" />
</intent-filter>
我的技术文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcB</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcF</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcV</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.IsoDep</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.MifareClassic</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.Ndef</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.NfcBarcode</tech>
</tech-list>
<tech-list>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.MifareUltralight</tech>
</tech-list>
</resources>
我也试过了:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:pathPattern="\\/nfc/..*"
android:scheme="http" />
</intent-filter>
还有:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:pathPattern="/nfc/.*"
android:scheme="http" />
</intent-filter>
甚至:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:scheme="http" />
</intent-filter>
还有:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="www.example.com"
android:pathPrefix="/nfc"
android:scheme="http" />
</intent-filter>
如果有人有一些建议如何使它工作或解释为什么它不可能,将不胜感激:)
【问题讨论】:
-
您是否验证了带有 URL 的记录已正确写入您的标签?字符集之类的东西...
-
是的,当我的活动被打开时,它显示:example.com/nfc/NFC00000001 但如果我的应用程序没有打开,应用程序不会单独启动。 PS http协议在stackoverflow中不可见lol
-
我理解那部分。我会验证(例如使用应用程序 NFC Taginfo)标签上实际包含哪些数据。
-
您最后一个版本的意图过滤器适用于我的 Android 6.0.1 三星 S7。
-
@corvairjo 嗯,它不适用于 OnePlus 3、Nexus 4 和 Nexus 6P...我没有其他设备要测试...
标签: android android-intent nfc intentfilter launching-application