How to find the screen is locked in android

后端 未结 6 1320
猫巷女王i
猫巷女王i 2020-12-03 11:47

For my application, I need to know that the screen is locked. How to check this is problematically. I used following flag:

if(WindowManager.LayoutParams.FLAG         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 11:50

    Register a broadcast receiver with action android.intent.action.ACTION_SCREEN_OFF and write your code in onReceive() method of receiver.

    If you are using an activity, onPause() will be called when the screen locked and onResume() will be called when the screen unlocked.

    In your code you are checking some flags, i don't know where you will do that checking ? is it continuous verification ? If you are using an activity in your app, the above procedure will happen, just check it in Android Developers website.

提交回复
热议问题