You can create that intent with the KeyguardManager
class, using the createConfirmDeviceCredentialIntent method available since API 21, it should be called from your activity with the startActivityForResult(intent)
method.
In your activity:
private static final int CREDENTIALS_RESULT = 4342; //just make sure it's unique within your activity.
void checkCredentials() {
KeyguardManager keyguardManager = this.getSystemService(Context.KEYGUARD_SERVICE);
Intent credentialsIntent = keyguardManager.createConfirmDeviceCredentialIntent("Password required", "please enter your pattern to receive your token");
if (credentialsIntent != null) {
startActivityForResult(credentialsIntent, CREDENTIALS_RESULT);
} else {
//no password needed
doYourThing();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Bundle data) {
if (requestCode == CREDENTIALS_RESULT) {
if(resultCode == RESULT_OK) {
//hoorray!
doYourThing();
} else {
//uh-oh
showSomeError();
}
}
}