This project provides fingerprint authentication functionality in an Android application. It allows users to log in using their fingerprints.
- Kotlin
- Android Jetpack Compose
- AndroidX Biometric Library
implementation("androidx.biometric:biometric:1.2.0")
To initialize the fingerprint authenticator, use the FingerPrintAuthenticator
class. You can check if the device is suitable for fingerprint authentication using the isFingerPrintAuthAvailable
function.
val fingerPrintAuthenticator = FingerPrintAuthenticator(context)
val status = fingerPrintAuthenticator.isFingerPrintAuthAvailable()
To start the fingerprint authentication prompt, use the promptFingerPrintAuth
function. This function takes callbacks that are called when authentication is successful, fails, or an error occurs.
fingerPrintAuthenticator.promptFingerPrintAuth(
title = "Login",
subtitle = "Use your fingerprint or face ID to login",
negativeButtonText = "Cancel",
fragmentActivity = activity,
onSuccess = {
message = "Success"
},
onFailed = {
message = "Wrong fingerprint or face ID"
},
onError = { _, errorMessage ->
message = "Canceled"
}
)
The FingerPrintAuthStatus enum class indicates the status of fingerprint authentication.
READY
: Fingerprint authentication is ready.NOT_AVAILABLE
: Fingerprint authentication hardware is not available.TEMPORARILY_UNAVAILABLE
: Fingerprint authentication is temporarily unavailable.AVAILABLE_BUT_NOT_ENROLLED
: Fingerprint authentication is available but no fingerprint or face ID is enrolled.