Android NFC,发现时将标签传递给不同的侦听器
我有一个 NFC 应用程序,它在清单中设置了所有正确的意图过滤器,仅响应特定类型的 NFC 技术。
这部分有效,但我不明白如果另一个应用程序具有完全相同类型的过滤器,它会做什么。
我的应用程序忽略除特定类型的标签之外的所有 nfc 标签,扫描时我的应用程序从 onDestroyed() (或根本不运行)弹出到 onCreate() 并从标签读取信息。
现在,这由我的标签中的信息进一步过滤,我放置了我的应用程序寻找的特殊类型的字符串。但不幸的是,这要求它在确定它是什么类型的技术之后读取标签。如果它不是我的字符串之一,该应用程序就会消失 - 但我不明白如果另一个应用程序正在寻找相同类型的技术会发生什么。
我希望发生的是,我的应用程序在看到此标签时加载,但在忽略它后消失。然后具有完全相同过滤器集的其他应用程序可以加载并处理该标签。但我不明白这是如何处理的,我可以预见许多 NFC 应用程序即将上市。
洞察力受到赞赏。
I have an NFC app that has all the proper intent filters set up in the manifest to only respond to a particular kind of NFC technology.
This part works, but I don't understand what it will do if ANOTHER app had the exact same kind of filters.
My app ignores all nfc tags except the ones of a particular type, when scanned my app pops up from onDestroyed() (or never run at all) to onCreate() and reads the info from the tag.
Now this is further filtered by the info in my tags, I put a special kind of string that my app looks for. But unfortunately this requires it to have read the tag AFTER determining what kind of technology it is. If it isn't one of MY strings, the app goes away - but I don't understand what would happen if another app was looking for the same kind of technology.
What I would prefer to happen is that my app is loaded when seeing this tag, but then goes away after ignoring it. THEN other apps with the exact same filter set could load and have their go at the tag. But I don't understand how this is handled, and I can foresee many NFC apps coming to market.
Insight appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大概,用户将看到一个活动选择器。
如果我的活动选择器猜测是正确的,那么实现这一点的唯一方法是:
用户在安装您的应用程序并点击相关标签后,选择您的应用程序作为此类 NFC 标签的默认处理程序,
您在确定这不是您的标签类型后,会弹出您自己的任何其他相关活动选择器Activity,通过使用
PackageManager
和queryIntentActivities()
等将自己从列表中过滤出来,
我预计大多数 NFC 应用程序将专注于 NDEF 兼容标签,这使得这变得更加简单。
Presumably, the user will be presented with an activity chooser.
If my activity chooser guess is correct, then the only way that this will be possible is if:
The user chooses your app to be the default handler for this type of NFC tag, after installing your app and tapping a relevant tag, and
You, after determining it is not your type of tag, pop up your own hand-rolled activity chooser for any other relevant activity, filtering yourself out of the list, by using
PackageManager
andqueryIntentActivities()
and suchI project that most NFC apps will be focused on NDEF-compatible tags, which make this a lot simpler.
活动选择器确实会显示是否有多个应用程序可以处理 ACTION_TECH_DISCOVERED 意图。如果我正确理解您的问题,您确实无法阻止活动选择器显示多个应用程序是否可以处理该标签,除非您使用前台调度,如果可能的话,如果您的应用程序位于前台,它可以让您的应用程序处理意图。它将取代任何其他可以处理它并且不显示活动选择器的应用程序。如果在检查数据并发现它不是您想要的标签后,我认为您可以广播该意图,以便其他应用程序可以尝试处理它。查看:
http://developer.android.com/ Guide/topics/nfc/advanced-nfc.html#foreground-dispatch
了解更多信息。
The Activity Chooser will indeed show if more than one application can handle the ACTION_TECH_DISCOVERED intent. If I understand your problem correctly, you really cannot stop the activity chooser from showing if multiple apps can handle the tag, unless you use foreground dispatching, which lets your application handle the intent, if possible, if your app is in the foreground. It will supersede any other app that can handle it and not show the activity chooser. If after checking the data and finding out its not the tag you want, I think you can potentially broadcast the intent so other apps can try to handle it. Check out:
http://developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch
for more information.