How can I set sound for notification for my android application. In my application notification will be shown after 30 seconds. I want to give options for this alerts such as silent mode, vibration mode and an option to select from the available tones from the device. I am using the preference screen to show the settings menu. I want to to set the notification ring type application specific. Is there any way to establish this..
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;
http://developer.android.com/reference/android/app/Notification.Builder.html#setSound(android.net.Uri)
Notification.Builder.setSound();
Use a ringtone preference in the preference activity to get the URI of the selected sound.
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