How can an Android listener be created to perform a task just before entering power save mode? Also: what are some of the low power options that can be controlled by this task?
3 Answers
The answer above(for API 21 and above) is not exactly right. You should register a receiver in your activity or service like this:
BroadcastReceiver powerSaverChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
checkPowerSaverMode();
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("android.os.action.POWER_SAVE_MODE_CHANGED");
registerReceiver(powerSaverChangeReceiver, filter);
The reason for this is that receivers in manifest are not triggered by this broadcast.
ACTION_POWER_SAVE_MODE_CHANGED
Intent that is broadcast when the state of isPowerSaveMode() changes. This broadcast is only sent to registered receivers.
I have tested this and it works.

- 1
- 1

- 206
- 2
- 2
-
Is there a way to simply check if device is in power save mode? – jmrodrigg Jan 20 '17 at 10:34
-
@jmrodrigg you can just use ```PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); boolean powerSave == m.isPowerSaveMode(); ``` – nattster Jan 24 '17 at 15:22
-
@nattster Thanks! – jmrodrigg Feb 02 '17 at 09:41
Since Lollipop (API 21) there is PowerManager#ACTION_POWER_SAVE_MODE_CHANGED broadcast intent.
So you need just to receive it:
AndroidManifest.xml:
<receiver android:name=".observers.PowerSaveModeReceiver">
<intent-filter>
<action android:name="android.os.action.POWER_SAVE_MODE_CHANGED"/>
</intent-filter>
</receiver>
PowerSaveModeReceiver.java:
public class PowerSaveModeReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
if (BuildConfig.DEV_LOGS)
Log.d(this.getClass().getName(), String.format("onReceive(context = [%s], intent = [%s])", context, intent));
final PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isPowerSaveMode()) {
// do something
} else {
// do some else
}
}
}
-
Does it work for you? It is written in the docs "This broadcast is only sent to registered receivers." ... – android developer Aug 30 '17 at 11:52
How can an Android listener be created to perform a task just before entering power save mode?
There is no broadcast Intent
for this. The closest is ACTION_SCREEN_OFF
. The device will likely fall asleep in the near future after you receive this broadcast. And, you can only listen for this broadcast using a BroadcastReceiver
registered via registerReceiver()
in an activity or service or other Context
.
Also: what are some of the low power options that can be controlled by this task?
I have no idea what this means, sorry.

- 986,068
- 189
- 2,389
- 2,491
-
Screen off is one part of power save that can be disabled in Settings > Applications > Development. Can other power save functions such as closing the microSD card interface be controlled by an application? – jacknad Nov 10 '10 at 12:11
-
@JackN: I am unclear what you think "closing the microSD card interface" is. Please see `android.provider.Settings.System` for the sorts of things you can control. Beyond that list, there is nothing power-related I can think of along the lines you seem to be interested in. – CommonsWare Nov 10 '10 at 13:21