gpt4 book ai didi

android - 在通知栏中设置没有图标的AlarmClock

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:42 25 4
gpt4 key购买 nike

要在 Android OS 6(又名 Marshmallow)中构建准确可靠的警报,我不得不使用 setAlarmClock报警管理器的方法。问题是此方法在顶部状态栏中显示警报图标。由于我的应用需要闹钟来在每天午夜刷新一些数据,它会一直显示闹钟图标,这很不愉快。

最佳答案

不幸的是,这完全是 Android 开发人员为了节省电池而有意设计的。当您查看 AlarmManager 方法的文档时,这个动机就会变得清晰。例如,此引用来自 AlarmManager#setExactAndAllowWhileIdle 上的文档:

These alarms can significantly impact the power use of the device when idle (and thus cause significant battery blame to the app scheduling them), so they should be used with care. To reduce abuse, there are restrictions on how frequently these alarms will go off for a particular application. Under normal system operation, it will not dispatch these alarms more than about every minute (at which point every such pending alarm is dispatched); when in low-power idle modes this duration may be significantly longer, such as 15 minutes. [emphasis mine]

因此,Google 希望您通过在状态栏中放置小闹钟来以某种方式向用户发出信号,表明您的应用可能正在耗电,如果您确实确实需要准确的闹钟。引自关于 AlarmManager#setAlarmClock 的文档:

As such, these types of alarms can be extremely expensive on battery use and should only be used for their intended purpose.

因此,您有以下两个选择:

  1. 使用AlarmManager#setExactAndAllowWhileIdle并接受最多 15 分钟的延迟
  2. 使用AlarmManager#setAlarmClock并接受闹钟

关于android - 在通知栏中设置没有图标的AlarmClock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33194640/

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