Carnal
Carnal

Reputation: 22064

Android - Notification alarm sound

I have implemented a notification with an alarm sound like this:

    PendingIntent pi = PendingIntent.getActivity(context, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    Notification note = new Notification(R.drawable.icon, "Alarm", System.currentTimeMillis());
    note.setLatestEventInfo(context, "Alarm", title + " (alarm)", pi);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if(alarmSound == null){
        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        if(alarmSound == null){
            alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        }
    }
    note.sound = alarmSound;
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.flags |= Notification.FLAG_AUTO_CANCEL;
    manager.notify(id, note);

The sound of the alarm plays, but the problem I'm facing is that it keeps playing all the time until I drag down the notification bar. While this is playing, I'm showing an activity as a dialog (popup) with some information about the current alarm playing. I want to be able to cancel this alarm sound in the button I have in the dialog (popup activity).

How can I achieve this? Thanks.

Upvotes: 1

Views: 6873

Answers (1)

tyczj
tyczj

Reputation: 74066

to cancel the sound just us manager.cancel(id) in your dialog button click the id is the id you set when you created the notification with manager.notify(id,note)

Upvotes: 1

Related Questions