2

I am trying to determine how an Android app can stop the phone from broadcasting NFC signals at any particular time.

I know that this is possible because I am using an app where when a particular modal screen is opened NFC no longer functions. I know this is happening because if I hold up the phone to my NFC reader when the modal is open, nothing is recognised. As soon as I close the modal, the NFC reader instantly picks up the device.

I am unsure how to integrate this into my app. I have read other answers including this one which seem to state it's not possible, which can't be true because I'm seeing it happen before my eyes.

Is NfcAdapter.enableReaderMode what I am looking for? I am trying to determine if this will work but as I'm unsure how to implement it I can't test it.

jskidd3
  • 4,609
  • 15
  • 63
  • 127
  • That app may be attempting [Android Beam](https://developer.android.com/guide/topics/connectivity/nfc/nfc#p2p) which would be sending a NFC message that the receiver in your video is unable to interpret. – Morrison Chang Nov 14 '18 at 15:24
  • @MorrisonChang That sounds plausible. If the app attempts Android Beam, would that stop the reader from detecting the phone? – jskidd3 Nov 14 '18 at 15:26
  • If the reader doesn't know how to deal with Android Beam, the default action may be do nothing which I believe is the desired behavior. You could always setup a Android Beam client on a different device to test that particular modal app. – Morrison Chang Nov 14 '18 at 15:30
  • @MorrisonChang It turns out `enableReaderMode` was correct as per my answer. – jskidd3 Nov 14 '18 at 17:11

1 Answers1

3

I managed to disable NFC by using enableReaderMode as I originally thought. After adding the code below into my React Native application's overridden onCreate method, I was able to disable NFC throughout the app.

import android.nfc.NfcAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
    adapter.enableReaderMode(this, null, NfcAdapter.STATE_OFF, null);
}
jskidd3
  • 4,609
  • 15
  • 63
  • 127
  • This is technically not correct because you're passing a STATE_ where a FLAG_ should be. I just so happens that that STATE_OFF value is the same as a FLAG_ value, and that putting it into reader mode even with that flag works by change. you should pass 0. – user9170 Mar 27 '20 at 15:59