Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NFC: enable and disable the NFC detected sounds

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:

  • Turn off device's NFC sound
  • Prevent alert tone when scanning / identifying an NFC intent
  • How do I disable/change the NFC sounds?

Some say that we can and some that we can't disable those sounds.

Can we disable and enable the NFC sound programmatically?

like image 273
Luong Truong Avatar asked Apr 28 '16 07:04

Luong Truong


People also ask

What is NFC on my Android?

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.

Should NFC be on or off?

NFC must be turned on for NFC-based apps (e.g., Android Beam) to function correctly.


1 Answers

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);
}
like image 175
Michael Roland Avatar answered Sep 19 '22 16:09

Michael Roland