For the Android OS, I need to find out what the user uses to unlock the device. Be it null, PIN, pattern, fingerprint.
Asked
Active
Viewed 1,729 times
2
-
Erm ...... why? – Stephen C Jun 02 '17 at 02:50
-
9Because the boss said so. – theAnonymous Jun 02 '17 at 02:54
-
Why did the boss say so? 'Cos this sounds like the kind of thing that could have (bad) security implications for the user. – Stephen C Jun 02 '17 at 03:43
-
Well yes ... but the considerations part may inform you if it is likely to be possible to do this. The functionality may not be supported *because of* the security and privacy considerations. At that point, knowing what you are actually trying to achieve might allow someone to suggest **better** alternatives to you / your boss. – Stephen C Jun 02 '17 at 04:40
1 Answers
4
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

ashkhn
- 1,642
- 1
- 13
- 18