Screen on/off detection

前端 未结 4 1138
遥遥无期
遥遥无期 2021-02-14 02:07

here i am trying to determine whether the screen is on or not but it doesn\'t seems to be working when press power lock/unlock button. Application works with no error but the co

4条回答
  •  再見小時候
    2021-02-14 02:13

    You can try adding this inside your activity.

    IntentFilter filter = new IntentFilter(); 
    filter.addAction(Intent.ACTION_SCREEN_OFF); 
    BroadcastReceiver mReceiver = new ScreenReceiver(); 
    registerReceiver(mReceiver, filter); 
    

    Similarly you can add for ACTION_SCREEN_ON also

提交回复
热议问题