1

I have problem with opening Complete action using pop up. When I detect NFC. I set activity in manifest before like this:

<action android:name="android.nfc.action.TECH_DISCOVERED" />
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<action android:name="android.nfc.action.TAG_DISCOVERED" />

And used NfcAdapter in MainMactivity. However, it doesn't seem like it's happening because of what I programmed. So, I deleted one by one. And tested. Now, I deleted all the code and settings of manifexts.xml related to NFC.

However, it is still working. I would call it outer NFC which is active everywhere. How can I turn it off? or avoid it? I don't even want its sound or vibration. I don't want it works.

However, I want it to be active in a specific fragment. Is it possible to behave like this?

c-an
  • 3,543
  • 5
  • 35
  • 82

1 Answers1

-1

How can I turn it off? or avoid it?

You need to call this method from main thread to disable system-level NFC implementation responsible for scanning and reading NFC tags> android.nfc.NfcAdapter#enableForegroundDispatch(); it would give control for scanning and reading/writing NFC tags over to your fragment/activity.

I want it to be active in a specific fragment. Is it possible to behave like this?

The above mentioned method will work for you to achieve this.

When you leave your application, you need to again disable the foreground dispatch(that you just enabled for your application) by calling android.nfc.NfcAdapter#disableForegroundDispatch().

Better approach is to hook these method calls inside onResume() and onPause() of a fragment/activity.

Jay
  • 2,852
  • 1
  • 15
  • 28
  • No, it is not working. And I can't even detect it. `enableForegroundDispatch()` and `disableForegroundDispatch()` can't do anything. Could you give me precise examples? – c-an Jul 02 '19 at 09:47
  • @c-an Post your code, please. I can't add anything further to my answer without knowing your implementation. – Jay Jul 02 '19 at 09:51
  • Well, I deleted all my code and settings related to `NFC`. I haven't implemented anything. And still `Complete action using` pop up comes up. – c-an Jul 02 '19 at 09:56
  • @c-an Please follow [NFC Basics](https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#dispatching) documentation to understand how kernel [dispatches NFC info to application layer](https://developer.android.com/guide/topics/connectivity/nfc/nfc.html#dispatching). By the way, you need to add those 3 NFC intents in manifest in order for the suggested solution to work. – Jay Jul 02 '19 at 10:01
  • I already read it and the explanation doesn't seem it is related to `Complete action using`. What I solve the problem is giving `SingleTop` for the `pendingIntent`. However, it is not working always. So, I want the real solution. – c-an Jul 02 '19 at 10:07
  • This solution doesn't work as per OP's requirements. – IgorGanapolsky Apr 16 '20 at 21:34