I am implementing Notification as below. Default Alarm sound is playing fine, but only for once. All i want is to play it repeatedly until the tap is registered.
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("I Am Fine")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(NOTIFICATION_MESSAGE))
.setContentText(NOTIFICATION_MESSAGE)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mBuilder.setSound(alarmSound,AudioManager.STREAM_MUSIC);
The second parameter to setSound doesn't showing any effect. Please help !
You have to use FLAG_INSISTENT for the notification. From the documentation:-
public static final int FLAG_INSISTENT
Bit to be bitwise-ored into the flags field that if set, the audio will be repeated until the notification is cancelled or the notification window is opened.
Constant Value: 4 (0x00000004)
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("title").setContentText("message")
.setSound(soundUri); // This sets the sound to play
Notification mNotification = mBuilder.build();
mNotification.flags |= Notification.FLAG_INSISTENT;
// Display notification
notificationManager.notify(1, mNotification);
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