I am trying to identify a single reliable callback that we get in Android when the device enters Doze mode. I tried the following:
IntentFilter filter = new IntentFilter();
filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ajitha", "intent action=" + intent.getAction()
+ " idleMode=" + pm.isDeviceIdleMode());
}
}, filter);
super.onResume();
In the above code sample the receiver is hit many times when the device is dozing. In my trial run, logcat showed following:
Line 103: 08-25 15:41:21.814 I/PowerManagerService( 845): Going to sleep due to power button (uid 1000)...
Line 114: 08-25 15:41:22.601 I/PowerManagerService( 845): Dozing...
Line 144: 08-25 15:41:36.834 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
Line 146: 08-25 15:41:37.458 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false
Line 150: 08-25 15:41:38.268 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
Line 154: 08-25 15:42:08.669 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false
Line 156: 08-25 15:42:09.287 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=true
Line 175: 08-25 15:42:58.935 I/PowerManagerService( 845): Waking up from dozing (uid 1000)...
Line 200: 08-25 15:42:59.273 D/ajitha ( 6985): intent action=android.os.action.DEVICE_IDLE_MODE_CHANGED idleMode=false
If the intent is hit so many times, I am not able to perform my actions depending on this intent. Is there any other intent that I can rely to identify the device entering doze???
Why is this intent hit so many times???