避免在活动中检测到nfc标签 [英] Avoid nfc tag getting detected in an activity

查看:322
本文介绍了避免在活动中检测到nfc标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,我的应用程序必须处理NFC.

I have a requirement wherein my application deals with NFC.

我已经在清单文件中声明了nfc.

I have declared nfc in the manifest file.

<uses-feature
    android:name="android.hardware.nfc"
    android:required="true"/>

现在,我的问题是,是否可以在特定活动中禁用nfc标签检测.

Now, my question is, Is it possible to disable the nfc tag detection in a specific activity.

例如,我有10个活动,但我不希望第5个活动检测nfc.是否有可能? 我需要同样的建议.

E.g., I have 10 activities and I don't want the 5th Activity to detect nfc. Is it possible? I need suggestions for the same.

推荐答案

您不能真正阻止设备检测NFC标签.但是,您可以做的是将活动设置为接收(然后忽略)所有NFC发现事件.

You cannot really stop the device from detecting NFC tags. What you can do, however, is to set your activity to receive (and then ignore) all NFC discovery events.

为此,您可以使用NfcAdapter的高级NFC:使用NFC前景调度系统有关如何进行此注册的信息.

To do this, you would register your activity with the NFC foreground dispatch system using the NfcAdapter's enableForegroundDispatch() method. This gives your current activity precedence in receiving NFC events over all other intent filters. See Advanced NFC: Using the NFC Foreground Dispatch System on how to do this registration.

一旦您注册了前台调度系统,您的活动将通过其onNewIntent()方法接收所有NFC目的(或作为待定目的结果,具体取决于您的注册方式).在这里,您可以简单地忽略这些事件.

Once you registered for the foreground dispatch system, your activity will receive all NFC intents in its onNewIntent() method (or as a pending intent result depending on how you register). There, you can simply ignore these events.

这篇关于避免在活动中检测到nfc标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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