How to Prompt User to Enter Pin in Android Lock Screen?

前端 未结 1 1390
故里飘歌
故里飘歌 2021-01-07 04:14

Android screen lock/ unlock programmatically

and

How to lock/unlock phone programmatically : Android

and many questions i have searched for answer b

1条回答
  •  执笔经年
    2021-01-07 04:55

    You can use the below code to open password/pin/pattern screen and validate user device credentials:

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
    
        if (km.isKeyguardSecure()) {
            Intent authIntent = km.createConfirmDeviceCredentialIntent(getString(R.string.dialog_title_auth), getString(R.string.dialog_msg_auth));
            startActivityForResult(authIntent, INTENT_AUTHENTICATE);
        }
    }
    

    and also implement onActivityResult's method to get the results in your case is successful or not.

    // call back when password is correct  
    @Override  
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == INTENT_AUTHENTICATE) {  
            if (resultCode == RESULT_OK) {  
                //do something you want when pass the security  
            }  
        }  
    }
    

    You can check ref URL from here

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