AlarmManager.AlarmClockInfo 的 PendingIntent 如何工作? [英] How does AlarmManager.AlarmClockInfo's PendingIntent work?

查看:31
本文介绍了AlarmManager.AlarmClockInfo 的 PendingIntent 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

此构造函数需要时间和 PendingIntent 文档中描述为:

<块引用>

可用于显示或编辑闹钟详细信息的意图.

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

<块引用>

警报响起时执行的操作

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

解决方案

但是,AlarmClockInfo 使用的 PendingIntent 是如何使用的,我该如何使用它来编辑闹钟的详细信息?

从)

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

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

The constructor to this takes the time and a PendingIntent which is described in the docs as:

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

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

Action to perform when the alarm goes off

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

解决方案

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 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 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.

这篇关于AlarmManager.AlarmClockInfo 的 PendingIntent 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆