I am trying to use AlarmManager.AlarmClockInfo
to set an alarm.
The constructor to this takes the time and a PendingIntent
which is descr
however, how is the PendingIntent used by AlarmClockInfo and how do I use it to edit the details of the alarm clock?
Quoting myself from this book:
The biggest issue with
setAlarmClock()
is that it is visible to the user:
The user will see the alarm clock icon in their status bar, as if they had set an alarm with their device's built-in alarm clock app
The user will see the time of the alarm when they fully slide open their notification shade
- Tapping on the alarm time in the notification shade will invoke the
PendingIntent
that you put into theAlarmClockInfo
object
So, given this code...:
static void scheduleAlarms(Context ctxt) {
AlarmManager mgr=
(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(ctxt, PollReceiver.class);
PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0);
Intent i2=new Intent(ctxt, EventDemoActivity.class);
PendingIntent pi2=PendingIntent.getActivity(ctxt, 0, i2, 0);
AlarmManager.AlarmClockInfo ac=
new AlarmManager.AlarmClockInfo(System.currentTimeMillis()+PERIOD,
pi2);
mgr.setAlarmClock(ac, pi);
}
(from this sample project)
...when the user taps on the time in the notification shade, EventDemoActivity
will appear. The idea is that you should supply an activity here that allows the user to cancel or reschedule this alarm.