문제

I have a requirement wherein my application deals with NFC.

I have declared nfc in the manifest file.

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

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

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.

도움이 되었습니까?

해결책

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.

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.

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.

다른 팁

You just call simply this one when your activity is destroy or pause

 nfcAdapter.disableForegroundDispatch(getActivity());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top