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.
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()
)
}
}
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.