首页 > 解决方案 > 使用 AlarmManager#setAlarmClock 安排闹钟时,Android 10 中没有闹钟登录

问题描述

我的应用程序是一个闹钟应用程序,我通过以下方式设置闹钟:

PendingIntent pendingIntent = PendingIntent.getBroadcast(Activity_AlarmsList.this, alarmID, intent, 0);

ZonedDateTime zonedDateTime = ZonedDateTime.of(alarmDateTime.withSecond(0), ZoneId.systemDefault());

alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(zonedDateTime.toEpochSecond() * 1000, pendingIntent), pendingIntent);

wherealarmDateTime是一个LocalDateTime包含警报日期和时间的对象。在 Android M 和 N(真实设备)上,一旦设置了闹钟,状态栏上就会出现闹钟标志。但在我的三星 Galaxy M31s (Android Q) 上,没有出现警报信号!但是当我在 Android Q 模拟器上运行应用程序时,会出现闹钟标志。

在三星 Galaxy M31s 中,如果我执行adb shell dumpsys alarm,我会得到以下输出:

Next wake from idle: Alarm{c9c59a type 0 when 1603225320000 in.basulabs.shakealarmclock}
tag=*walarm*:in.basulabs.shakealarmclock.DELIVER_ALARM
type=0 expectedWhenElapsed=+48s986ms expectedMaxWhenElapsed=+48s986ms whenElapsed=+48s986ms maxWhenElapsed=+48s986ms when=2020-10-21 01:52:00.000
window=0 repeatInterval=0 count=0 flags=0x3
Alarm clock:
  triggerTime=2020-10-21 01:52:00.000
  showIntent=PendingIntent{f26a278: PendingIntentRecord{9c3ed51 in.basulabs.shakealarmclock broadcastIntent}}
operation=PendingIntent{860e9b6: PendingIntentRecord{9c3ed51 in.basulabs.shakealarmclock broadcastIntent}}

这就是我想要的。就这样定了闹钟,果然闹钟也响了,但是没有闹钟的标志出现。

问题是什么?

标签: androidalarmmanagerandroid-10.0

解决方案


推荐阅读