Android: How to enable notification sound using sound resource?

Looking at the developer documentation, I see how to use the default sound and how to use Uri , but I don’t see how to use the resource. How can I use one of the sounds in my folder res/raw? For example, an MP3 or WAV file?

+5
source share
3 answers
Uri path = Uri.parse("android.resource://[package]/[res id]");

Example:

Uri path = Uri.parse("android.resource://com.mypackage/"+R.raw.mysound_1);
+19
source
Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound);

Add to Notification Designer

.setSound(soundUri)
+2
source

You were probably looking for:

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.your_sound);
0
source

All Articles