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

点点圈 提交于 2019-12-20 05:41:24

问题


Android screen lock/ unlock programmatically

and

How to lock/unlock phone programmatically : Android

and many questions i have searched for answer but i didn't got the exact answer for my usage.

I would like to get a enter credentials or Enter pin page in Lock Screen Default System Lock Screen. When we say Ok Google the Google will prompt to enter the credentials .

I need the same time. I m asking just to wipe out screen and enter credentials

Give me the answer which would for All android versions.


回答1:


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



来源:https://stackoverflow.com/questions/52504272/how-to-prompt-user-to-enter-pin-in-android-lock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!