DiChrist
DiChrist

Reputation: 361

Checking if user has enrolled facial recognition

I have an application that checks if the user has facial recognition and fingerprint recognition for biometric purposes.

I have to do two checks for each type of biometric.

Check 1 - Check if the device supports the specified biometric.

Check 2 - Check if the user has used the biometric with biometric registration.

I have two methods to do this for me:

private fun isFaceEnrolled(): Boolean {
        val packageManager = packageManager
        val biometricManager = BiometricManager.from(this)

        val hasFaceHardware = packageManager.hasSystemFeature(PackageManager.FEATURE_FACE)

        val canAuthenticateWithFace = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG) == BiometricManager.BIOMETRIC_SUCCESS

        return hasFaceHardware && canAuthenticateWithFace
    }

    private fun isFingerprintEnrolled(): Boolean {
        val packageManager = packageManager
        val biometricManager = BiometricManager.from(this)

        val hasFingerprintHardware = packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)

        val canAuthenticateWithFingerprint = biometricManager.canAuthenticate(
            BiometricManager.Authenticators.BIOMETRIC_STRONG
        ) == BiometricManager.BIOMETRIC_SUCCESS

        return hasFingerprintHardware && canAuthenticateWithFingerprint
    }

I had a problem with a test where the device supports facial biometrics but the user's face is not scanned, i.e., he/she did not use this biometric.

Even so, the "isFaceEnrolled" method is returning true.

Is there something in it that I didn't check correctly?

Upvotes: 0

Views: 61

Answers (1)

user27894462
user27894462

Reputation: 319

Your code is only checking face recognition/fingerprint capabilities of the device. That's why it's returning true because the device has face recognition/fingerprint support. Once the user register face recognition/fingerprint, you need to manually save the value, preferably to a sharedpreference file (if you want the value to persist even after the app is finished) and then access that value from sharedpreference file when you want to check whether Face recognition/fingerprint is registered or not. Your current code can't help you with that as it's only a basic way to check device capabilities regarding FR/FP. It's not designed to save app specific registration values

Upvotes: 1

Related Questions