Kevassi Kevassi - 6 months ago 62
Android Question

Detecting Doze State

Is it possible to detect when a device enters Doze/Standby? I haven't been able to find anything in the Android documentation about a possible Broadcast Receiver or Listener that I could enable or create in order to receive notifications of these transitions.

Answer

I believe the Intent you're looking for is ACTION_DEVICE_IDLE_MODE_CHANGED. From the documentation:

Intent that is broadcast when the state of isDeviceIdleMode() changes. This broadcast is only sent to registered receivers.

The documentation for isDeviceIdlemode is as follows:

Returns true if the device is currently in idle mode. This happens when a device has been sitting unused and unmoving for a sufficiently long period of time, so that it decides to go into a lower power-use state. This may involve things like turning off network access to apps. You can monitor for changes to this state with ACTION_DEVICE_IDLE_MODE_CHANGED.

Returns

Returns true if currently in active device idle mode, else false. This is when idle mode restrictions are being actively applied; it will return false if the device is in a long-term idle mode but currently running a maintenance window where restrictions have been lifted.

This gist is also a good read. Link is now dead.