android - 将我的 NFC 标签绑定(bind)到我的应用程序

标签 android nfc mime-types intentfilter ndef

android 开发者指南说

Activities should register the most specific intent filters possible to avoid the activity chooser dialog, which can disrupt the interaction with the tag as the user interacts with the screen.

我正在开发一个应该只获取他的 MIME 类型的应用程序,并且不显示 Activity 选择器真的很重要,但我想知道:如果在同一设备中有一个通用 NFC 阅读器会发生什么应用程序? Activity 选择器会显示还是我的应用程序会启动?

最佳答案

具有与 NDEF 数据匹配的最具体 Intent 过滤器的应用程序将获胜。因此,如果您注册了一个 MIME 类型为 text/plain 的记录,而另一个 Activity 只注册了任何 NDEF 数据(android.nfc.action.NDEF_DISCOVERED,没有任何数据规范),您的 Activity 将自动显示。

但是请注意,如果一个 Activity 注册为 NDEF_DISCOVERED + MIME 类型 text/plain 而第二个 Activity 注册为 NDEF_DISCOVERED + MIME输入 text/*,两个 Intent 过滤器将被视为相同,并且将显示一个 Activity 选择器。

一般来说,您可能更喜欢 NFC 论坛外部类型而不是 MIME 类型,因为这些类型允许您为您的记录类型指定一个唯一的域。

关于android - 将我的 NFC 标签绑定(bind)到我的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19769825/

相关文章:

android - 由于gradle问题,如何修复 “Unable to load class ' Dagger 。

node.js - 读取 MIFARE Classic 卡的第二个扇区及更多扇区时出现错误 6800

android - Android API 方法 CardEmulation.getInstance() 的 UnsupportedOperationException

PHP 图像生成器因任何典型原因而失败

c# - 从原始 http 请求中读取多部分内容

android - Android 中的 ViewPager + RecyclerView 问题

android - 如何从 Edittext 中检索多行文本?

nfc - NFC标签存储大小

android - 基于android中的文件启动Activity

java - Android MVVM 与数据绑定(bind)