How does AlarmManager.AlarmClockInfo PendingIntent work?

I am trying to use AlarmManager.AlarmClockInfo to set an alarm.

The constructor for this takes time and a PendingIntent , which is described in the documents as:

An intention that can be used to display or edit alarm details.

and then setAlarmClock( ) also takes a pending intent, which is described in the docs as:

The action taken when the alarm is turned off

I understand the use of PendingIntent on setAlarmClock( ) , however, how is PendingIntent used by AlarmClockInfo and how to use it to edit alarm details?

+7
android android-pendingintent
source share
1 answer

however, how is PendingIntent used by AlarmClockInfo and how to use it to edit alarm details?

Quote from this book :

The biggest problem with setAlarmClock() is that it is visible to the user:

  • The user will see the alarm icon in the status bar, as if they set an alarm with their built-in alarm device.

  • The user will see the alarm time when they fully open their notification shade.

Notification Shade, Showing Upcoming Alarm

  • Clicking on the alarm time in the shadow of the notification will call the PendingIntent , which you put in the AlarmClockInfo 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 closes the time in the shade of the notification, EventDemoActivity will appear. The idea is that you must provide activity here that allows the user to cancel or reschedule this signal.

+11
source share

All Articles