I am currently implement a feature where the users are requested to ignore battery optimisation for the application. The reason for doing so, is that the main functionality of the application is unfortunately drastically affected by power save mode.
To achieve my goal, I prompt the users by creating an Intent
and setting the Action
to ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
.
Although, before firing the Intent
, I both check for isPowerSaveMode()
and isIgnoringBatteryOptimizations()
to ensure that I don't prompt the users when power save mode is not enabled; which is a requirement for the feature. The way I do so is by:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isPowerSaveMode = pm.isPowerSaveMode(); // always returns false for Huawei devices
This works fine for the most devices, but for Huawei devices, isPowerSaveMode()
always returns false
. Consequently, since the preconditions fail, the prompt is never shown.
Has anyone else possibly encountered this issue? If so, what did you do to solve it?
As a note, the same issue is also present in the Xamarin.Android
SDK.
false
when requestingisPowerSaveMode()
even though it was enabled. My thought is that the flag is exposed in a different way compared to other manufacturers, such as Samsung (which works fine). But that's just a theory. – Retsina