Issue
Is it possible to use the default security settings, which user has set to the phone, as a locking or login mechanism for my app too? I mean like when we reset the phone, it asks for phone password or pattern.
Is it possible the same way that I can use the default android password or pattern set by user to login to my app?
My goal is to bypass the developing effort and use some standard way of authentication without making user to remember another new password.
NOTE: I'm aware that I can lock the screen programmatically. But instead, I want to use the lock as a verification before performing any critical operation. (Just like how Settings ask for the password before resetting the the phone.)
Solution
Actually, there is an API to exactly that using the KeyguardManager.
First get a the Keyguard SystemService:
KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
And then request an authentication intent using:
Intent i = km.createConfirmDeviceCredentialIntent(title,description);
start this intent using startActivityForResult(Intent, int)
and check for RESULT_OK
if the user successfully completes the challenge.
This is for API level 21.
Previous versions might work with KeyguardLock
.
Answered By - agi
Answer Checked By - Terry (JavaFixing Volunteer)