AlarmManager.SetExactAndAllowWhileIdle 方法

定义

例如 #setExact(int, long, PendingIntent),即使系统处于低功率空闲模式,也允许执行此警报。

[Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLandroid/app/PendingIntent;)V", "GetSetExactAndAllowWhileIdle_IJLandroid_app_PendingIntent_Handler", ApiSince=23)]
[Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")]
public virtual void SetExactAndAllowWhileIdle (Android.App.AlarmType type, long triggerAtMillis, Android.App.PendingIntent operation);
[<Android.Runtime.Register("setExactAndAllowWhileIdle", "(IJLandroid/app/PendingIntent;)V", "GetSetExactAndAllowWhileIdle_IJLandroid_app_PendingIntent_Handler", ApiSince=23)>]
[<Android.Runtime.RequiresPermission("android.permission.SCHEDULE_EXACT_ALARM")>]
abstract member SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit
override this.SetExactAndAllowWhileIdle : Android.App.AlarmType * int64 * Android.App.PendingIntent -> unit

参数

type
AlarmType

警报类型。

triggerAtMillis
Int64

警报应关闭的时间(以毫秒为单位),使用适当的时钟(具体取决于警报类型)。

operation
PendingIntent

警报关闭时要执行的操作;通常来自 PendingIntent#getBroadcast IntentSender.getBroadcast().

属性

注解

例如 #setExact(int, long, PendingIntent),即使系统处于低功率空闲模式,也允许执行此警报。 如果你不需要确切的警报计划,但仍需要在空闲时执行,请考虑使用 #setAndAllowWhileIdle。 这种类型的警报必须<>仅用于<>实际要求警报在空闲时关闭的情况 -- 一个合理的示例是日历通知,应该发出声音,以便用户知道它。 调度警报时,应用还将添加到系统的临时电源豁免列表中约 10 秒,以允许该应用程序获取完成其工作的进一步唤醒锁。</p>

这些警报可能会显著影响空闲时设备的电源使用(从而导致对应用进行计划的重要电池指责),因此它们应谨慎使用。 为了减少滥用,对特定应用程序这些警报的频率有限制。 在正常系统操作下,它不会每分钟发送一次以上的警报(此时会调度每个待定警报):在低功率空闲模式下时,持续时间可能会明显更长,例如 15 分钟。

与其他警报不同,系统可以自由地重新安排这种类型的警报,以便与其他任何警报一起无序发生,即使是来自同一应用。 当设备处于空闲状态时(由于此警报可以在空闲时关闭,当应用的任何其他警报将保持到以后)时,这显然会发生,但即使未空闲,也可能发生这种情况。 请注意,OS 将允许自己更灵活地安排这些警报,而不是常规确切的警报,因为应用程序已选择使用此行为。 当设备处于空闲状态时,可能需要更多自由,以便优化电池使用时间。

<p class=“note”><strong Note:</strong>> Starting withBuild.VERSION_CODES#S, apps targeting SDK level 31 or higher need to request the Manifest.permission#SCHEDULE_EXACT_ALARM SCHEDULE_EXACT_ALARM permission to use this API, 除非应用不受电池限制。 用户和系统可以通过“设置”中的特殊应用访问屏幕撤销此权限。

<p class=“note”><strong Note:</strong>> Exact alarms only be used for user-facing features. 有关详细信息,请参阅 “精确警报”权限

即使应用位于后台,也允许通过此 API 计划的警报启动前台服务。

适用于 . 的 android.app.AlarmManager.setExactAndAllowWhileIdle(int, long, android.app.PendingIntent)Java 文档

本页的某些部分是根据 Android 开放源代码项目创建和共享的工作进行的修改,并根据 Creative Commons 2.5 属性许可证中所述的术语使用。

适用于