API 21 has this new method AlarmManager.setAlarmClock (...) , which sets a new alarm and displays the alarm status icon.
I use it as follows:
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(ALARM_ALERT_ACTION);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setAlarmClock(new AlarmManager.AlarmClockInfo(time, sender), sender);
The problem is that I do not know how to cancel this signal because this code does not work:
am.cancel(PendingIntent.getBroadcast(context, 0, new Intent(ALARM_ALERT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT));
The alarm itself is canceled (my BroadcastReceiver onReceive is not called), but the status bar alarm icon is still displayed, and AlarmManager.getNextAlarmClock () returns this alarm.
source
share