我已经实现了一个带有警报声的通知,如下所示:
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);
闹钟的声音响起,但我面临的问题是它一直在播放,直到我向下拖动通知栏。播放时,我将活动显示为对话框(弹出窗口),其中包含有关当前警报播放的一些信息。我希望能够在对话框(弹出活动)中的按钮中取消此警报声。
我怎样才能做到这一点?谢谢。