3

Is there a way to play built-in sound effects programmatically? I want to play the NFC sound effect when my app scans an NFC tag (success sound effect and failure sound effect).

Mark Buikema
  • 2,483
  • 30
  • 53

1 Answers1

2

Im just pasting code from the accepted answer that is in - StackOverflow question to play Android Notification sound

try {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
    r.play();
} catch (Exception e) {
    e.printStackTrace();
}
Community
  • 1
  • 1
karthik prasad
  • 738
  • 7
  • 15