警报管理器在多个设备中不工作 [英] AlarmManager not working in several devices

查看:37
本文介绍了警报管理器在多个设备中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序使用 AlarmManager,并且它从 4 年前就开始工作了.但我注意到它在某些设备上开始出现故障.

My app uses AlarmManager and it has been working since 4 years ago. But I noticed it started failing in some devices.

我很确定代码是正确的(我使用 WakefulBroadcastReceiver 和 setExactAndAllowWhileIdle 用于打盹设备),因为它在 Nexus 设备上运行良好,但在某些制造商(华为、小米...)的设备上却失败了.

I'm pretty sure code is right (I'm using WakefulBroadcastReceiver, and setExactAndAllowWhileIdle for devices with Doze) because it's working perfectly on Nexus devices, but it fails in devices of some manufacturers (Huawei, Xiaomi...).

例如,华为设备有一种电池管理器可以杀死应用程序,当应用程序被杀死时,预定的警报会被取消.因此,在华为电池管理器中将应用设置为受保护"即可解决问题.

Huawei devices, for example, have a kind of battery manager that kill apps, and when an app is killed, scheduled alarms are cancelled. So setting an app as "protected" in Huawei battery manager solves the problem.

但最近我注意到它不适用于更多设备:小米、三星(可能与新的智能管理器"有关?)……这种行为似乎正在成为一种标准:杀死后台应用程序.

But recently I noticed it's not working with more devices: Xiaomi, Samsung (maybe it's related to the new "Smart Manager"?)... It seems that this behavior is becoming a standard: to kill background apps.

有人知道吗?有什么方法可以确保触发警报?

Anyone know anything about it? Any way to ensure alarm is fired?

此问题是由不同制造商添加的节电器"引起的.更多信息请访问:https://dontkillmyapp.com/

This problem is caused by "battery savers" added by different manufacturers. More info here: https://dontkillmyapp.com/

推荐答案

我已经在尝试解决它几个星期了.我什么也没找到.华为只是在一段时间后关闭所有警报.如果我将应用程序放在他们的节电程序中受保护的应用程序中,则无济于事.但是,如果我将应用程序的包名称更改为包含闹钟、时钟或日历之类的词,它就可以像在任何其他设备上一样正常工作.我不明白 Google 如何为这种垃圾提供认证.我认为OEM不应该以这种方式修改核心平台.我知道他们有自己的电池保护程序,当用户不使用它时,它会在一段时间后杀死该应用程序.但这也会对受保护的应用程序发出终止警报.

I'm trying to solve it several weeks already. I found nothing. Huawei just kill all the alarms after some time. If I put the app to the protected app in their battery saver it does't help. But If I change package name of my app to contain words like alarm, clock or calendar, it works absolutely normal like on any other devices. I don't understand how Google can give certification for this crap. I think that OEM should not modify core platform in such way. I understand that they have own batter saver which kill the app after some time, when user don't use it. But this killing alarms also of protected apps.

另外 setAlarmClock() 对精确定时警报也有帮助.但是不可能将它用于像小部件更新这样的想法.

Also setAlarmClock() for exact timing alarms helps. But it is not possible to use this for thinks like widget update.

更新:包名关键字保护已经不适用于当前的华为设备,2017 年确实如此.

这篇关于警报管理器在多个设备中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆