How to ask user to unlock device on clicking notification action in android?

后端 未结 2 1463
别跟我提以往
别跟我提以往 2021-01-02 22:09


      I am displaying a notification from my application and this notification has an action in it, when user clicks on the action, the c

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-02 22:36

    In the Activity you are opening (that is behind the lock screen) you should tell system to lift the keyguard (e.g. in onCreate())

    For API >= 26

    KeyguardManager km = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
    km.requestDismissKeyguard(this, null); // you may add callback listener here
    

    For API < 26:

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    

    If device is not locked securely it would unlock it immediately, and if it is locked, it will ask user to do it.

提交回复
热议问题