I am implementing Biometric authentication using BiometricPrompt class.
- how to check is hardware is available or not before calling
BiometricPrompt#authenticate
method? - how to check has enrolled biometric?
How to call BiometricManager#canAuthenticate
method?
I can't create object for BiometricManager class in kotlin
My current implementation follows.
val executor = Executors.newSingleThreadExecutor()
val biometricPrompt = BiometricPrompt(this, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
Log.d("BIOMETRIC", "$errString $errorCode")
if (BiometricPrompt.ERROR_HW_NOT_PRESENT == errorCode || BiometricPrompt.ERROR_NO_BIOMETRICS == errorCode)
PreferenceHandler.setBiometricAvailable(this@LockActivity, false)
else
PreferenceHandler.setBiometricAvailable(this@LockActivity, true)
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Log.d("BIOMETRIC", "FAILED")
}
})
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("App title")
.setSubtitle("")
.setDescription("Identify yourself by Biometrics")
.setNegativeButtonText("Use Password")
.build()
biometricPrompt.authenticate(promptInfo)