如何读取已附加到设备的NFC标签 [英] How to read an NFC tag which is already attached to the device

查看:368
本文介绍了如何读取已附加到设备的NFC标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是读取已附加到设备上的NFC标签.

My requirement is to read an NFC tag which is already attached to the device.

我在应用程序中观察到以下内容:

I observed the following in my application:

已将NFC标签粘贴到设备上,并且NFC已关闭.然后,当我启动我的Android应用程序时,它将要求打开NFC,并且在打开NFC之后,我的应用程序将读取已附加到设备上的NFC标签.

An NFC tag is already attached to the device and NFC is off. When I then launch my Android app it will ask to turn on the NFC and, after turning on NFC, my app will read the NFC tag that was already attached to the device.

已将NFC标签粘贴到设备上,并且NFC处于打开状态.然后,当我手动启动我的应用程序时,它不会检测到NFC标签.

An NFC tag is already attached to the device and NFC is on. When I then launch my app manually, it will not detect the NFC tag.

为什么在后一种情况下应用未检测到NFC标签?在启动应用程序之前(手动),有什么方法可以检测和读取已经粘贴到设备上的标签吗?

Why is the NFC tag not detected by the app in the latter case? Is there any way to detect and read a tag that was already attached to the device before the app is started (manually)?

推荐答案

通常这是不可能的.如果标签是新发现的,则Android只会将标签分发给应用(即,标签刚刚被点击).因此,启动应用程序后,应用程序将无法访问NFC阅读器字段中已经存在的标签.

In general that's not possible. Android only dispatches a tag to an app if the tag is newly discovered (i.e. the tag has just been tapped). Thus, apps cannot access tags that were already in the field of the NFC reader when the app is launched.

由于Android NFC API不允许在应用程序内禁用和重新启用NFC功能(只能通过设置"应用程序完成),因此也无法暂时禁用NFC阅读器来欺骗Android可以检测到标签是刚被窃听的.

Since the Android NFC API does not allow the NFC feature to be disabled and re-enabled from within an app (this can only be done through the Settings app), its also not possible to temporarily disable the NFC reader to trick Android into detecting the tag as freshly tapped.

但是,在Android版本> = 4.4和< 5.1(或者是<6.0?)在NFC读取器模式API(

However, on Android version >= 4.4 and < 5.1 (or was that < 6.0?) there is a bug (undocumented feature?) in the implementation of the NFC reader-mode API (enableReaderMode() that causes tags to be redecteded after enabling reader-mode. Consequently, on these Android versions you could use enableReaderMode() to rediscover already-attached tags. Be warned though that while this works in AOSP, some device manufacturer-specific modifications of Android might not contain this bug/feature.

这篇关于如何读取已附加到设备的NFC标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆