Android NFC:拦截所有标签
我希望我的应用程序拦截手机发现的所有标签。这样我想检查标签的 uid 并随后传递意图(显示应用程序选择器等)。
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
这就是我目前清单中的内容,以及 TAG_DISCOVERED 的意图过滤器:
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.Ultralight</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
当我扫描 Mifare 智能卡时,我的应用程序会被调用,当我对 NXP ICODE IC 使用不同的标签时,会启动标准 Android 标签应用程序。
关于如何确保我能够看到所有标签的任何提示?
I want my app to intercept all tags discovered by the phone. That way I want to check the uid of the tag and pass on the intent afterwards (show an application chooser etc.).
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
Thats what I currently have in my manifest, along with a intent filter for TAG_DISCOVERED:
<tech-list>
<tech>android.nfc.tech.NfcA</tech>
<tech>android.nfc.tech.NfcB</tech>
<tech>android.nfc.tech.NfcF</tech>
<tech>android.nfc.tech.NfcV</tech>
<tech>android.nfc.tech.IsoDep</tech>
<tech>android.nfc.tech.MifareClassic</tech>
<tech>android.nfc.tech.Ultralight</tech>
<tech>android.nfc.tech.Ndef</tech>
<tech>android.nfc.tech.NdefFormatable</tech>
</tech-list>
When I scan a Mifare Smartcard, my app gets called, when i use different tags with NXP ICODE ICs, the standard android tag app is launched.
Any hint on how I can ensure that I get to see ALL tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,技术列表的工作方式是将列出的所有技术进行 AND 组合在一起,这意味着如果标签列出了所有不同的技术,则意图将传递给应用程序。我不知道有哪个这样做。你想做的是更多:
等等。这对您想要的不同标签进行或运算。 (NfcA 或 NfcB 等)现在,其中一些技术可以结合在一起,例如 NfcA 和 Ultralight 或 Ndef。因此,如果您想捕获一张 NfcA 和 Ndef 的卡,您可以使用
Now,与标签上的技术最匹配的应用程序将启动,或显示在选择菜单中。但 NDEF_DISCOVERED 的优先级高于 TECH_DISCOVERED。现在,NDEF_DISCOVERED 意图启动器可以非常具体地指定传递哪些标签。虽然 NDEF 的某些格式(如 Mime 类型)允许“捕获所有”过滤器(例如,Mime 的“/”),但有些则不允许。 (就像 uri 格式的 Ndef 记录一样)。对于这些,如果有一个特定的应用程序针对它,除非您知道它并内置它,否则您将无法保证您的应用程序将会启动。另外,我从来没有能够拥有多个 Ndef 标签的意图过滤器(Mime 或 URI,但不能同时使用两者)。但这可能是我还不够努力。
如果另一个应用程序尝试执行相同的操作(捕获尽可能多的标签),您将始终被调用。因此,除非您手机上有唯一的应用程序,否则不可能捕获每个标签。但是像上面看到的那样格式化你的技术列表代码会让你更接近。
First off, the way a tech-list works is that all the tech's listed are ANDed together, meaning the intent is passed to the app if the tag has ALL the different techs listed. I don't know of any that do. what you are wanting to do is more:
and so on. This ORs the different tags you want. (NfcA or NfcB etc.) Now some of these tech's go together, like NfcA and Ultralight or Ndef. So if you want to catch a card that is NfcA and Ndef you would use
Now, the app that most closely matches the tech on the tag would launch, or be shown in a selection menu. But NDEF_DISCOVERED gets priority over TECH_DISCOVERED. Now the NDEF_DISCOVERED intent launcher can be very specific in what tags get passed on. While some formats of NDEF (Like Mime type) allow for "catch all" filters (example, "/" for Mime), some do not. (like for a uri formatted Ndef Record). For those, if there is a specific app targeting it, unless you know it and build it in, you won't be able to guarantee that your app will be launched. Also I've never been able to have more than one intent filter for Ndef tags (Mime OR URI, but not both). But that could be that I haven't tried hard enough.
And if another app tries to do the same (catch as many tags as possible), you will always be called up with it. So there is no possible way of catching every single tag, unless you have the only app on the phone. But formatting your tech-list code like you see above will get you a lot closer.
理论上,您可以通过前台调度来做到这一点:
http:// developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch
您需要处理所有 NDEF_DISCOVERED MIME 类型(/),然后是所有 TECH_DISCOVERED 标记技术以及 TAG_DISCOVERED 意图。您的应用程序必须位于前台。否则,您无法保证您的应用程序启动,因为任何其他应用程序始终可以处理与您的应用程序相同的意图,因此将出现活动选择器。
You can theoretically do this with foreground dispatching:
http://developer.android.com/guide/topics/nfc/advanced-nfc.html#foreground-dispatch
You need to handle all NDEF_DISCOVERED MIME types (/), then all TECH_DISCOVERED tag technologies, as well as the TAG_DISCOVERED intent. Your app must be in the foreground. You cannot do guarantee your app is started otherwise because any other app can always handle the same intent as your app, and therefore the activity chooser will appear.