Android 2.3.6 和 4.x 的 NFC 检测不同
我发现,当我将 Nexus S(运行 Android 2.3.6)放在包含 NDEF 消息且带有指向网站的 URI 记录的 NFC 标签旁边时,这会导致(如预期)显示 NFC 活动选择器(因为我安装了多个 NFC 读取器应用程序,并且我正在开发自己的应用程序,该应用程序也拦截检测到的 NFC 标签)。
但是,使用 Galaxy Nexus(Android v4、冰淇淋三明治)时,不会出现活动选择器。它会直接启动浏览器。 LogCat 将显示以下内容:
D/NfcService(438): TAG: Tech [android.nfc.tech.MifareUltralight, android.nfc.tech.NfcA, android.nfc.tech.Ndef]
I/ActivityManager(196): START {flg=0x10008000 cmp=com.android.nfc3/com.android.nfc.NfcRootActivity (has extras)} from pid 438
I/ActivityManager(196): START {act=android.nfc.action.NDEF_DISCOVERED dat=http://www.someURL.com/someotherstuff cmp=com.google.android.browser/com.android.browser.BrowserActivity (has extras)} from pid 438
所以这给了我两个问题:
a) Android 2.3.6 和 4.x 决定表现不同,因为……?
b)即使当我尝试限制我的应用程序仅匹配包含 www.someURL.com 主机的 NFC 标签时,即通过放入
<data
android:host="www.someURL.com"
android:pathPattern="/*"
android:scheme="http" />
我的 3 个意图过滤器(一个用于 TAG_DISCOVERED,一个用于 TECH_DISCOVERED,一个用于 NDEF_DISCOVERED),我真的尝试吸引 NFC 活动选择器的注意力..),结果不会改变。它只会打开浏览器。 ATM 唯一有效的是前台调度...
有什么想法吗?
I discovered that when I put the Nexus S (running Android 2.3.6) next to a NFC tag which contains an NDEF message with an URI-record pointing to a web-site, this will cause (as expected) that the NFC activity chooser is shown (as I have several NFC reader apps installed, and I'm working on my own application that also intercepts detected NFC tags).
However, using the Galaxy Nexus (Android v4, Ice Cream Sandwich), the activity chooser does NOT appear. It will simply directly launch the browser. LogCat will show this:
D/NfcService(438): TAG: Tech [android.nfc.tech.MifareUltralight, android.nfc.tech.NfcA, android.nfc.tech.Ndef]
I/ActivityManager(196): START {flg=0x10008000 cmp=com.android.nfc3/com.android.nfc.NfcRootActivity (has extras)} from pid 438
I/ActivityManager(196): START {act=android.nfc.action.NDEF_DISCOVERED dat=http://www.someURL.com/someotherstuff cmp=com.google.android.browser/com.android.browser.BrowserActivity (has extras)} from pid 438
So this gives me two questions:
a) Android 2.3.6 and 4.x decide to behave differently, becaaaause...?
b) Even when I try to restrict my application to match only NFC tags that contain the www.someURL.com host, i.e. by putting
<data
android:host="www.someURL.com"
android:pathPattern="/*"
android:scheme="http" />
into my 3 intent-filters (one for TAG_DISCOVERED, one for TECH_DISCOVERED, one for NDEF_DISCOVERED, I really tries to grab the NFC activity chooser's attention there..), the result won't change. It will just open the browser. ATM the only thing that works is Foreground-dispatching...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能应该使用“android:pathPrefix”而不是“android:pathPattern”。您现在匹配 0 次或多次出现“/”...
You should probably use "android:pathPrefix" instead of "android:pathPattern". You are now matching 0 or more occurrences of "/"...
您的观察是正确的:
因为在 Android 4.0.x 中,传入 NDEF 消息的行为已得到简化,以获得更好的用户体验。 Android 检测一些消息类型并将数据直接传递到内置应用程序。
我很确定这是针对转到浏览器的 URI 记录和转到联系人应用程序的 VCard 消息完成的,但也可能有其他消息。
您可以通过启用前台调度并让您的应用程序以焦点方式运行来覆盖此内置行为。
Your observation is correct:
Because with Android 4.0.x the behaviour for incoming NDEF-messages have been streamlined for a better user-experience. Android detects a few messages types and passes the data directly to the built-in applications.
I'm pretty sure this is done for URI-records which go to the browser and VCard messages that go to the contact application, but there could be other messages as well.
You can override this built-in behaviour by enabling foreground dispatch and having your application running with focus.