Android M listening to android.os.action.DEVICE_IDLE_MODE_CHANGED

前端 未结 2 371
既然无缘
既然无缘 2021-02-04 15:57

Can a third party application get an action once the device goes in to Doze mode?

Trying to register Broadcast receiver for below action,



        
2条回答
  •  心在旅途
    2021-02-04 16:56

    To confirm what was mentioned in the comments, defining the android.os.action.DEVICE_IDLE_MODE_CHANGED broadcast receiver via the AndroidManifest.xml has no effect.

    The only way to register the receiver is to do it dynamically:

    IntentFilter filter = new IntentFilter();
    filter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
    context.registerReceiver(new BroadcastReceiver()
    {
      @Override
      public void onReceive(Context context, Intent intent)
      {
        onDeviceIdleChanged();
      }
    }, filter);
    

提交回复
热议问题