Check if android is in energy saving

2

I wonder if I can check if the android device is energy-saving. I've looked everywhere, including the official documentation, and nothing.

    
asked by anonymous 08.10.2016 / 16:48

1 answer

6

Starting from version 21 (Lollipop) you can check power save mode using the isPowerSaveMode () of the PowerManager (which deals with the power state control issues of the device), it will return true if the device is in "power save mode".

It is also possible to monitor changes in mode. Register a BroadcastReceiver to respond to the 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 for AndroidManifest.xml

<receiver android:name=".PowerSaveModeReceiver">
    <intent-filter>
        <action android:name="android.os.action.POWER_SAVE_MODE_CHANGED"/> 
    </intent-filter>
</receiver>
    
08.10.2016 / 17:14