How to Prompt User to Enter Pin in Android Lock Screen?
Asked Answered
O

1

4

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.

Optics answered 25/9, 2018 at 18:2 Comment(0)
P
10

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

Pickpocket answered 25/9, 2018 at 18:12 Comment(2)
I m asking about in Lockscreen. You are referring to lockscreen security prompt in my app when it is in open.Optics
hey @Arsal : How to achieve same thing in Flutter? please helpJobey

© 2022 - 2024 — McMap. All rights reserved.