Skip to content

Instantly share code, notes, and snippets.

@vinodbaste
Created May 7, 2022 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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