gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:57:46 27 4
gpt4 key购买 nike

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

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

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

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

Action to perform when the alarm goes off

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

最佳答案

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

Notification Shade, Showing Upcoming Alarm

  • 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 。

关于android - AlarmManager.AlarmClockInfo 的 PendingIntent 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34699662/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com