Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for Power Saver Mode programmatically

I have written an app (AutoWifiSwitch) and one of the features I plan to add is automatically disabling the wifi scanning service in my app if power saving mode is enabled.

I know Android L is supposed to have Battery Saving implemented (previously HTC and Samsung would add the features themselves to the software). Presumably this now means Google will have added some sort of API for it. Ideally there would be a new action added so I could listen for that.

I would also like to know if the above is possible with HTC/Samsung APIs and if so, how do I use them.

I've been searching everywhere for the above questions but had absolutely no luck, the app SecureSettings (an addon for Tasker) is able to hook into the HTC/Samsung APIs to enable the power saver anyway, I'm not quite sure how they do it.

Edit: The power saver value can be gotten from the PowerManager in Android L, not sure if there is an Action for it though.

like image 714
Keir Nellyer Avatar asked Jul 31 '14 17:07

Keir Nellyer


2 Answers

PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
boolean powerSaveMode = powerManager.isPowerSaveMode();

Docs: developer.android.com/.../PowerManager#isPowerSaveMode()

Added in API level 21 (Android 5.0)

like image 166
user2851150 Avatar answered Sep 27 '22 21:09

user2851150


It did not work for me on my Samsung S8, Android 9, instead I used:

  • to set: $adb shell settings put global low_power 1
  • to get: $adb shell settings get global low_power

...and it worked!

Translating it into java it goes something like this:

final String result = Settings.Global.getString(getContentResolver(),"low_power");
like image 34
Pol Clota Avatar answered Sep 27 '22 22:09

Pol Clota