AlarmManager.AlarmClockInfo 的 PendingIntent 是如何工作的?

How does AlarmManager.AlarmClockInfo's PendingIntent work?

我正在尝试使用 AlarmManager.AlarmClockInfo 设置闹钟。

这个的构造函数需要时间和 PendingIntent,在文档中描述为:

an intent that can be used to show or edit details of the alarm clock.

然后 setAlarmClock( ) 也接受了一个未决的意图,在文档中描述为:

Action to perform when the alarm goes off

我了解 setAlarmClock( )PendingIntent 的使用,但是 AlarmClockInfo 如何使用 PendingIntent 以及如何使用它来编辑详细信息闹钟?

however, how is the PendingIntent used by AlarmClockInfo and how do I use it to edit the details of the alarm clock?

引自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 the AlarmClockInfo object

所以,鉴于此代码...:

  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);
  }

(来自 this sample project

...当用户点击通知栏中的时间时,将出现EventDemoActivity。这个想法是你应该在这里提供一个 activity 允许用户取消或重新安排这个警报。