I am dealing with NFC tags. My problem is that I cannot turn off the sound when NFC tags are detected. I started my research and also started getting confused:
Some say that we can and some that we can't disable those sounds.
Can we disable and enable the NFC sound programmatically?
Near Field Communication (NFC) is a set of short-range wireless technologies, typically requiring a distance of 4cm or less to initiate a connection. NFC allows you to share small payloads of data between an NFC tag and an Android-powered device, or between two Android-powered devices.
NFC must be turned on for NFC-based apps (e.g., Android Beam) to function correctly.
Starting with API level 19 (Android 4.4) you can disable the NFC sounds while your app is in the foreground by using the newer reader-mode API to listen for NFC tags. The reader-mode API has a flag FLAG_READER_NO_PLATFORM_SOUNDS
that can be used to disable the NFC discovery sounds.
@Override
protected void onResume() {
super.onResume();
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
adapter.enableReaderMode(this,
new NfcAdapter.ReaderCallback() {
@Override
public void onTagDiscovered(final Tag tag) {
// do something
}
},
NfcAdapter.FLAG_READER_NFC_A |
NfcAdapter.FLAG_READER_NFC_B |
NfcAdapter.FLAG_READER_NFC_F |
NfcAdapter.FLAG_READER_NFC_V |
NfcAdapter.FLAG_READER_NFC_BARCODE |
NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS,
null);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With