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

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

问题描述

我正在尝试使用AlarmManager.AlarmClockInfo设置警报.

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

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

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.

,然后setAlarmClock( )也接受待处理的意图,在文档中将其描述为:

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

警报响起时执行的操作

Action to perform when the alarm goes off

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

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?

推荐答案

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

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

这本书中引用自己:

setAlarmClock()的最大问题是它对 用户:

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

  • 在通知栏上点击警报时间将调用 您放入AlarmClockInfo对象的PendingIntent
  • 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);
  }

(来自此示例项目)

...当用户在通知阴影中点击时间时,将出现EventDemoActivity.想法是您应该在此处提供一个活动,以允许用户取消或重新安排此警报.

...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天全站免登陆