androidbattery-saver

PoweSavingMode Vs App optimization


I need to know if there is any battery saving policy with the whole system or specific to my app.

I found out that you can check if the Power Saving Mode is activated or not by calling:

PowerManager oPowerManager = (PowerManager) oContext.getSystemService(Context.POWER_SERVICE);
boolean bActivated = oPowerManager.isPowerSaveMode();

But, how can I find out if my app is on the App optimization list?


Solution

  • Call isIgnoringBatteryOptimizations() on PowerManager. Quoting the documentation:

    Return whether the given application package name is on the device's power whitelist. Apps can be placed on the whitelist through the settings UI invoked by ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS.