Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Android default sound effect

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).

like image 646
Mark Buikema Avatar asked Jul 04 '26 20:07

Mark Buikema


1 Answers

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();
}
like image 153
karthik prasad Avatar answered Jul 07 '26 10:07

karthik prasad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!