The easiest way is to use the new version of Biometric under AndroidX.
You can easily know if the device allows you to use Biometric and under what type (FACE, FINGERPRINT, IRIS, MULTIPLE...). The library also provides a CryptoObject implementation if you want to implement it on your side on CryptoHelper.
To used this usefull library you can grab it via Gradle:
implementation 'com.mikhaellopez:biometric:1.1.0'
val biometricHelper = BiometricHelper(fragment)
// BiometricType = FACE, FINGERPRINT, IRIS, MULTIPLE or NONE
val biometricType: BiometricType = biometricHelper.getBiometricType()
// Check if biometric is available on the device
btnStart.visibility = if (biometricHelper.biometricEnable()) View.VISIBLE else View.GONE
btnStart.setOnClickListener {
biometricHelper.showBiometricPrompt(
BiometricPromptInfo(
title = "Title", // Mandatory
negativeButtonText = "Cancel", // Mandatory
subtitle = "Subtitle",
description = "Description",
confirmationRequired = true
)
) {
// Do something when success
}
}
You can also handle error and failed like this:
biometricHelper.showBiometricPrompt(promptInfo,
onError = { errorCode: Int, errString: CharSequence ->
// Do something when error
}, onFailed = {
// Do something when failed
}, onSuccess = { result: BiometricPrompt.AuthenticationResult ->
// Do something when success
})
Dark Mode | Biometric Fingerprint | Old Fingerprint |
---|---|---|
Find this library useful? Support it by joining stargazers for this repository ⭐️
And follow me for my next creations 👍
Biometric by Lopez Mikhael is licensed under a Apache License 2.0.