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

后端 未结 2 1440
别跟我提以往
别跟我提以往 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:29

    Use Activity intent in pending intent insted of Service

    Intent intent = new Intent(context, MyActivity.class);
    intent.putExtra(key, "my_value"); //Used to send information to action class
    PendingIntent pi = PendingIntent.getActivity(context, 0, intent,
                                     PendingIntent.FLAG_UPDATE_CURRENT);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题