Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out unlock method programmatically?

For the Android OS, I need to find out what the user uses to unlock the device. Be it null, PIN, pattern, fingerprint.

like image 693
theAnonymous Avatar asked Aug 27 '26 20:08

theAnonymous


1 Answers

To Detect if an authenticated fingerprint exists:

FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);

if (fingerprintManagerCompat.isHardwareDetected() && fingerprintManagerCompat.hasEnrolledFingerprints()) { 
    // Device supports fingerprint authentication and has registered a fingerprint     
} 

To use this you also need to add a permission

<uses-permission android:name="android.permission.USE_FINGERPRINT" />

To check if lock pattern is enabled:

ContentResolver cr = getContentResolver();

int lockPatternEnable = Settings.Secure.getInt(cr, Settings.Secure.LOCK_PATTERN_ENABLED, 0);
// If user has pattern unlock then lockPatternEnable will be 1 else 0

There is no explicit way to check for pin/password as far as I'm aware but you can use KeyGuardManager's isDeviceSecure() method

which returns true if device is secured with a PIN, pattern or password. Coupled with the pattern check you can detect if pin is enabled.

Remember to test for fingerprint first because it requires a pin/password unlock to be set as well

like image 76
ashkhn Avatar answered Aug 30 '26 11:08

ashkhn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!