As @JayShortway answered the backwards-compatible dependency is:
implementation 'androidx.biometric:biometric:1.0.0-alpha02'
But the implementation is different from the android.hardware.biometrics.BiometricPrompt
implementation:
class BiometricsManagerImpl {
private val executor = MainThreadExecutor()
override fun authenticate(activity: FragmentActivity) {
val prompt = BiometricPrompt(
activity,
executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
// Handle authentication errors
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
// Authentication Succeeded
}
})
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric Authentication")
.setDescription("Please authenticate in order to verify your identity")
.setNegativeButtonText("Cancel")
.build()
prompt.authenticate(promptInfo)
}
inner class MainThreadExecutor : Executor {
private val handler = Handler(Looper.getMainLooper())
override fun execute(runnable: Runnable) {
handler.post(runnable)
}
}
}