22

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.

stkent
  • 19,772
  • 14
  • 85
  • 111
Kevassi
  • 247
  • 1
  • 3
  • 10

1 Answers1

30

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.

Community
  • 1
  • 1
stkent
  • 19,772
  • 14
  • 85
  • 111
  • interesting? is it expected to indicate the right value in doze mode as well? given that any cpu work actually stops [to even run this method], from what I know. – Rajat Sharma Mar 17 '17 at 07:43
  • 2
    looks like doze and idle are not the same. as confusing as that can be – Rajat Sharma Mar 19 '17 at 10:25
  • 2
    it is confusing indeed. so is this intent going to be fired before the phone enters doze mode? – lelloman Aug 15 '17 at 12:10
  • 3
    Per docs https://developer.android.com/training/monitoring-device-state/doze-standby#testing_doze_and_app_standby the command to enter doze mode is `adb shell dumpsys deviceidle force-idle` so I assume that `idle` mode is the same as `doze` mode. – Mixaz Oct 22 '18 at 09:46
  • my brain exploded :) isDeviceIdlemode = false is actually the period where I should do things . It is when it resumes from Doze to process messages ? – user1937012 Mar 19 '21 at 17:00