Android: How to specify only Face recognition dialog on BiometricPrompt?

1.7k views Asked by At

I need to implement biometric login via touchid and faceid, that allows the user to choose which one he/she want to enable, either Touch or Face recognition.

I used the latest android library (androidx.biometric:biometric) to achieve this but having trouble on separating touch and face on promt.

Below image shows my problem. enter image description here

Here's my code:

private fun displayBiometricPrompt(
    activity: FragmentActivity,
    biometricCallback: BiometricCallback
) {
    context.let {
        val biometricPrompt = BiometricPrompt(
            activity,
            it?.mainExecutor!!,
            object : BiometricPrompt.AuthenticationCallback() {

                override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
                    super.onAuthenticationSucceeded(result)
                    biometricCallback.onAuthenticationSuccessful()
                }

                override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
                    super.onAuthenticationError(errorCode, errString)
                    biometricCallback.onAuthenticationError(errorCode, errString)
                }

                override fun onAuthenticationFailed() {
                    super.onAuthenticationFailed()
                    biometricCallback.onAuthenticationFailed()
                }
            }
        )
        biometricPrompt.authenticate(
            BiometricPrompt.PromptInfo.Builder()
                .setTitle(title)
                .setSubtitle(subtitle)
                .setDescription(description)
                .setConfirmationRequired(false)
                .setNegativeButtonText(negativeButtonText)
                .build()
        )
    }
}
1

There are 1 answers

2
Victor Cold On

There is no way to specify the type. Iris and face scanners supported only from Android 10. Before that, only fingerprints are available.

If the device has several sensors, each of them is defined as "weak" or "strong", "reliable". The Biometric API chooses which sensor is the most reliable and offers it to the user by default.