isIgnoringBatteryOptimizations not working for Samsung

2.5k views Asked by At

I am testing my new app and I have an issue with the

isIgnoringBatteryOptimizations

feature.

When the app starts it checks if the app is whitelisted for Doze. If not, it displays a message to the user because the app needs to be alive and cannot not be killed.

It works well for several devices and emulators but I am having 2 SAMSUNG devices for testing and in those cases the value of isIgnoringBatteryOptimizations is always false. Not matter what the user does (adding the app to the ignore list of doze and all that) the app always thinks that is being optimized so it always displays a warning message. Any ideas what could be wrong for those Samsung devices?

This is the code I use:

PowerManager oPowerManager = (PowerManager) MyContext.getSystemService(Context.POWER_SERVICE);
boolean b = oPowerManager.isIgnoringBatteryOptimizations( MyContext.getPackageName() );

"b" is always false for the Samsung devices I have tested.

1

There are 1 answers

0
Corey On

Mine did the same on an S5, but after a reboot of the phone, it now works.