How to find the screen is locked in android

后端 未结 6 1324
猫巷女王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:49

    Here is what I did:

    This handles if the user has unlocked the screen, but not yet entered the home screen or the user's screen is turned off say during a call.

               if (Intent.ACTION_SCREEN_ON.equals(pIntent.getAction()) ||  
                         Intent.ACTION_USER_PRESENT.equals(pIntent.getAction())) {
                    if(mListener!=null) {
                        KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
                        boolean locked = km.inKeyguardRestrictedInputMode();
                        Log.v(TAG, ": Phone lock state from KEYGUARD_SERVICE: Current state:" + (locked ? "LOCKED":"UNLOCKED"));
                        mIsPhoneLocked = locked;
                    }
                }
    

提交回复
热议问题