Check if android is in energy saving

Asked

Viewed 70 times

2

I wonder if there is a way to check if the android device is energy-saving. I’ve searched everywhere, including the official documentation, and nothing.

1 answer

6

From version 21(Lollipop) it is possible to check the power save mode through the method isPowerSaveMode() class Powermanager (which deals with the control issues of the device’s energy state), it will return true if the device is in "power save mode".

It is also possible to monitor changes in the mode. Register a Broadcastreceiver to respond to Intent ACTION_POWER_SAVE_MODE_CHANGED.
It will be released whenever there is a change in power save mode.

public class PowerSaveModeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {

        final PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powerManager.isPowerSaveMode()) {
            // está em "power save mode"
        } else {
            // não está em "power save mode"
        }
    }
}

Register on Androidmanifest.xml

<receiver android:name=".PowerSaveModeReceiver">
    <intent-filter>
        <action android:name="android.os.action.POWER_SAVE_MODE_CHANGED"/> 
    </intent-filter>
</receiver>
  • 1

    It helped me a lot, but not enough :/. I want to use some feature that works for all API’s

  • 1

    To emphasize the answer, add a Powermanager link. + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.