setAlarmclock()不是精确的,系统会调整时间的时间

发布于 2025-01-28 22:59:54 字数 1470 浏览 2 评论 0原文

setalarmclock的Android文档:

将来确切的时间调用警报。由于这些警报对用户高度可见,因此系统永远不会调整其交付时间。该系统将这些警报视为最关键的警报,并在必要时留下低功率模式。

但是看起来系统确实会调整警报的交付时间。

代码(Kotlin):

val intent = Intent(context, AlarmService::class.java)
val pendingIntent = PendingIntent.getService(context, 0, intent, 0)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager

alarmService.setAlarmClock(AlarmManager.AlarmClockInfo(epochMillis, null), intent)

设置了一分钟的警报,但是系统对其进行了调整。 必须在20:34:26中调用它,但实际上它将在20:45:28 dump>

dump('adb shell dumpsys armart'命令'命令中。 0设备):

Batch{68ad18a num=1 start=1468562132 end=1468562132 flgs=0x3}:
    RTC_WAKEUP #0: Alarm{faf73fb type 0 when 1652550328316 io.pelmenstar.testalarm}
      tag=*walarm*:io.pelmenstar.testalarm.START_ALARM
      type=0 whenElapsed=+11m58s237ms when=2022-05-14 20:45:28
      window=0 repeatInterval=0 count=0 flags=0x3
      Alarm clock:
        triggerTime=2022-05-14 20:34:26
        showIntent=null
      operation=PendingIntent{71cf62a: PendingIntentRecord{8d1cc1b io.pelmenstar.testalarm.startService}}

i 部分解决了问题。如果转到App Power -aver Manager(设置 - >电池 - > App Power -aver Manager--> 某些应用程序)并禁用“计划的背景唤醒”,则系统确实可以不调整此应用程序的警报。

问题是如何在不禁用“计划背景唤醒”选项的情况下解决问题,或者如何在运行时或安装时间(无用户交互)中禁用此选项。我注意到在某些应用程序(例如Facebook)上,此选项被禁用,但我自己没有这样做。

Android documentation for setAlarmClock:

Invoke an alarm at a precise time in the future. Because these alarms are highly visible to users, the system never adjusts their delivery time. The system identifies these alarms as the most critical ones and leaves low-power modes if necessary to deliver the alarms.

But it looks like system does adjust delivery time of alarm.

Code(Kotlin):

val intent = Intent(context, AlarmService::class.java)
val pendingIntent = PendingIntent.getService(context, 0, intent, 0)
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager

alarmService.setAlarmClock(AlarmManager.AlarmClockInfo(epochMillis, null), intent)

The alarm was set for a minute, but system adjusted it.
It must be invoked in 20:34:26, but actually it will be invoked in 20:45:28

Dump ('adb shell dumpsys alarm' command on Android 8.1.0 device):

Batch{68ad18a num=1 start=1468562132 end=1468562132 flgs=0x3}:
    RTC_WAKEUP #0: Alarm{faf73fb type 0 when 1652550328316 io.pelmenstar.testalarm}
      tag=*walarm*:io.pelmenstar.testalarm.START_ALARM
      type=0 whenElapsed=+11m58s237ms when=2022-05-14 20:45:28
      window=0 repeatInterval=0 count=0 flags=0x3
      Alarm clock:
        triggerTime=2022-05-14 20:34:26
        showIntent=null
      operation=PendingIntent{71cf62a: PendingIntentRecord{8d1cc1b io.pelmenstar.testalarm.startService}}

I partially resolved the problem. If go to the App Power-saver manager (Settings -> Battery -> App power-saver manager -> Some application) and disable 'Scheduled background wake-up', the system really do not adjust alarms of this application.

The question is how to resolve the problem without disabling 'Scheduled background wake-up' option or how to disable this option in runtime or install time (without user interaction). I noticed that on some apps (like Facebook) this option is disabled, but I didn't do that myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文