Looking at the developer documentation, I see how to use the default sound and how to use a Uri, but I don't see how to use a resource. How can I use one of the sounds in my res/raw
folder? Such as an MP3 or WAV file?
You can easily customize notification sounds for a text message, email, or system notification on your Galaxy phone. You can also set notification sounds with downloaded music files.
From the main list of message threads, tap “Menu” then choose “Settings“. Select “Notifications“. Select “Sound“, then choose the tone for text messages or choose “None“. You may also select “Vibrate” to turn vibration on or off.
Uri path = Uri.parse("android.resource://[package]/[res id]");
Example:
Uri path = Uri.parse("android.resource://com.mypackage/"+R.raw.mysound_1);
Uri soundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound);
Add to notification builder
.setSound(soundUri)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With