How to Set a Custom Sound for an Android Notification
Posted By : Sapna Sharma | 30-Jun-2015
Place a .mp3 or .wav file in your res/raw directory such as "notification_sound.mp3" as in the example below (the filename must not use capital letters).
Set the Notification.sound when you create your Notification, like this:
final int iconResId = R.drawable.my_icon;
final int soundResId = R.raw.notification_sound;
final Notification notification =
new Notification(iconResId, tickerText, System.currentTimeMillis());
final String packageName = context.getPackageName();
notification.sound =
Uri.parse("android.resource://" + packageName + "/" + soundResId);
Optionally, add vibration to your Notification:
notification.defaults = Notification.DEFAULT_VIBRATE;
THANKS
More From Oodles
Neha N | 14-Mar-2025
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Sapna Sharma
Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.