Skip to content

Instantly share code, notes, and snippets.

@vinodbaste
Created May 7, 2022 17:03
Show Gist options
  • Save vinodbaste/05c07cddb9d2a35a3817eeb6e6373724 to your computer and use it in GitHub Desktop.
Save vinodbaste/05c07cddb9d2a35a3817eeb6e6373724 to your computer and use it in GitHub Desktop.
fun initBiometricPrompt(
activity: AppCompatActivity,
listener: BiometricAuthListener
): BiometricPrompt {
// 1
val executor = ContextCompat.getMainExecutor(activity)
// 2
val callback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
listener.onBiometricAuthenticationError(errorCode, errString.toString())
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Log.w(this.javaClass.simpleName, "Authentication failed for an unknown reason")
}
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
listener.onBiometricAuthenticationSuccess(result)
}
}
// 3
return BiometricPrompt(activity, executor, callback)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment