Edward Hartnett
Edward Hartnett

Reputation: 961

How do I programmatically play the Android NFC notification sound?

I have an app (NFC Sniffer) which allows users to read NFC tags. When a user attempts to read a tag, 1 of 3 things happens:

  1. Nothing, the tag was not brought close enough
  2. Detected NFC, but fails to read card, in which case a notification tone is played.
  3. Reads tag, in which case a different notification sound is played.

Lots of new users are confused about these notification sounds. I want my program to have a help screen, with buttons to play these two sounds.

But how do I locate and play these two notifications from my code?

Upvotes: 2

Views: 2287

Answers (1)

Michael Roland
Michael Roland

Reputation: 40869

You can get these sounds from the sources of the AOSP project and include them in your own app. The sounds are part of the NFC system service app:

https://android.googlesource.com/platform/packages/apps/Nfc/+/master/res/raw/

Btw. starting with Android 4.4, you can disable the sounds while your activity is in the foreground by using the reader mode API with the flag NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS.

Upvotes: 4

Related Questions