Detect device is secured with pin lock or fingerprint lock of face lock?

Viewed 826

My application contains user authentication for login(includes pin/pattern, fingerprint unlock) which depends on device security. I am using Biometric manager to detect whether device has fingerprint support using BiometricManager and also checking whether device is secured using isDeviceSecure(). I am in need to detect in which mode mobile device is secured whether pin/pattern with, pin/pattern with fingerprint, pin/pattern with face unlock or all the three modes(pin/pattern, face unlock, fingerprint).

1 Answers

here is the code to detect what lock type is set

add lib to build.gradle

implementation 'androidx.biometric:biometric:1.0.0-beta01'

and this code to your activity

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean keyguardSecure = keyguardManager.isKeyguardSecure();
Log.e("---", "checkSecurityTypes: keyguardLocked - " + keyguardSecure);//true = pin/pattern

int i = BiometricManager.from(this).canAuthenticate();
Log.e("---", "checkSecurityTypes: " + i);//true 0 = pin/pattern with finger print

switch (i) {
    case BiometricManager.BIOMETRIC_SUCCESS:
        Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
        Log.e("MY_APP_TAG", "No biometric features available on this device.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
        Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
        // Prompts the user to create credentials that your app accepts.
        break;
}

if (i == 0 && keyguardSecure) {
    //fingerprint is always with pin/pattern/password
    Log.e("---", "checkSecurityTypes: fingerprint is set with pin/pattern");
} else if (keyguardSecure) {
    //true if pin/pattern/password is set
    Log.e("---", "checkSecurityTypes: pin/pattern is set");
}

we can't detect face type. for more see this link

Related