Android NFC: enable and disable the NFC detected sounds
Asked Answered
G

1

8

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?

Gwin answered 28/4, 2016 at 7:44 Comment(0)
W
18

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);
}
Woodsy answered 2/5, 2016 at 7:26 Comment(4)
thank you for your answer, this is exactly what i am looking for.Gwin
For some strange reason this didn't work. But putting the FLAG_READER_NO_PLATFORM_SOUNDS first on tags seemed to do the trick :)Underbid
perfect solution i was looking for. thanksSisyphean
Thank you for your answer Michael. How can I transact APDUs from/to card using this code? IsoDep is not working for me!Dorene

© 2022 - 2024 — McMap. All rights reserved.