3

How to make the app get user to auth himself with the phone's PIN or whatever using KeyGuard if the phone is under SDK 21?

I want something like KeyguardManager#createConfirmDeviceCredentialIntent, but for under SDK 21.

theAnonymous
  • 1,701
  • 2
  • 28
  • 62

2 Answers2

0

There's no equivalent functionality before API 21. If you wish to force a lock of the device and an unlock of the user, you would have to implement your own Device Administration app (or component of an app) and require the user have it installed. Then you could call DevicePolicyManager.lockNow() to force the screen to be locked. Using the device admin framework you can also require the user to have certain secure password/PIN requirements.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
-1

you can use this lib https://github.com/stfalcon-studio/SmsVerifyCatcher

Download via Gradle:

compile 'com.github.stfalcon:smsverifycatcher:0.3.1’

Usage Add permissions to AndroidManifest.xml:

Init SmsVerifyCatcher in method like onCreate activity:

smsVerifyCatcher = new SmsVerifyCatcher(this, new OnSmsCatchListener<String>() {
    @Override
    public void onSmsCatch(String message) {
        String code = parseCode(message);//Parse verification code
        etCode.setText(code);//set code in edit text
        //then you can send verification code to server
    }
});

Override activity lifecicle methods:

@Override
protected void onStart() {
    super.onStart();
    smsVerifyCatcher.onStart();
}

@Override
protected void onStop() {
    super.onStop();
    smsVerifyCatcher.onStop();
}

/**
 * need for Android 6 real time permissions
 */
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    smsVerifyCatcher.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

You can set phone number filter:

smsVerifyCatcher.setPhoneNumberFilter("777");

or set message filter via regexp:

smsVerifyCatcher.setFilter("");