Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AlarmManager not working in several devices

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

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?

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

like image 373
Sergio Viudes Avatar asked Jan 11 '16 19:01

Sergio Viudes


2 Answers

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.

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

Update: Protection by package name keywords is already not working on current Huawei devices, it was true in 2017.

like image 118
ATom Avatar answered Oct 16 '22 10:10

ATom


The issue is Smart Manager. Samsung has a battery manager which at times disables certain apps from running in background. It tried to "resume" when going back to the app but completely disables the application or may resume every 5 mins or so (depending how Samsung has it).

This would work on stock versions of android as there is no Samsung Manager. You can also install custom version of android which has some features to enable SM (depending on the rom).

like image 10
S A Avatar answered Oct 16 '22 10:10

S A