问题
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