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

About Author

Author Image
Sapna Sharma

Sapna is a bright Android Apps developer using Titanium framework. Sapna likes music and helping needy people.

Request for Proposal

Name is required

Comment is required

Sending message..