1 year ago
#315994
Sparsh Dutta
Ask for only either Face ID or Fingerprint Id in Android app
I want an implementation such that if both Face ID and fingerprint ID is enabled in user's device - my app will ask for authentication with Face ID, if only Face ID is enabled in user's device - my app will ask for authentication with Face ID, and if only fingerprint ID is enabled in user's device - my app will ask for fingerprint ID.
Right now, my app authenticates with both fingerprint ID and Face ID, if both are enabled in user's device.
I am using the following code snippets:
//BELOW CODE IS SUPPOSED TO CHECK IF AUTHENTICATION WITH FINGERPRINT IS POSSIBLE
var canAuthenticateFingerprint = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG)
//BELOW CODE IS SUPPOSED TO CHECK IF AUTHENTICATION WITH Face ID IS POSSIBLE
var canAuthenticateFaceAuth = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK)
//BELOW CODE STORES IN PREFERENCES THE FLAG FOR SUPPORTED AUTHENTICATION METHODS
if (canAuthenticateFingerprint == BIOMETRIC_SUCCESS
&& canAuthenticateFaceAuth == BIOMETRIC_SUCCESS)
{
prefsUseCase.setFaceSecurityEnabled(true)
prefsUseCase.setFingerprintSecurityEnabled(true)
}
else if (canAuthenticateFaceAuth == BIOMETRIC_SUCCESS
&& canAuthenticateFingerprint != BIOMETRIC_SUCCESS)
{
prefsUseCase.setFaceSecurityEnabled(true)
prefsUseCase.setFingerprintSecurityEnabled(false)
}
else if (canAuthenticateFingerprint == BIOMETRIC_SUCCESS
&& canAuthenticateFaceAuth != BIOMETRIC_SUCCESS){
prefsUseCase.setFaceSecurityEnabled(false)
prefsUseCase.setFingerprintSecurityEnabled(true)
}
//BELOW CHECKS IF Face ID OR FINGERPRINT AUTHENTICATION IS SUPPORTED OR NOT AND
//TAKES APPROPRIATE ACTION
var canAuthenticate = biometricManager.
canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_WEAK
or BiometricManager.Authenticators.BIOMETRIC_STRONG)
when (canAuthenticate) {
BiometricManager.BIOMETRIC_SUCCESS -> {
confirmBiometrics()
}
else -> sendNavigateToHomePageEvent()
}
}
//BELOW METHOD IS SUPPOSED TO USE AUTHENTICATION WITH EITHER FACE ID OR FINGERPRINT //ID
private fun getPromptInfo(): BiometricPrompt.PromptInfo {
if ((prefsUseCase.isFaceSecurityEnabled() &&
prefsUseCase.isFingerprintSecurityEnabled())
|| prefsUseCase.isFaceSecurityEnabled()) {
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use passcode")
.setAllowedAuthenticators(BIOMETRIC_WEAK)
.build()
}
else if ((prefsUseCase.isFingerprintSecurityEnabled() &&
!prefsUseCase.isFaceSecurityEnabled())){
promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use passcode")
.setAllowedAuthenticators(BIOMETRIC_STRONG)
.build()
}
return promptInfo
}
How do I make it such that only one authentication method according to my requirement, as mentioned in beginning of this post, is used instead of both?
android
fingerprint
android-biometric-prompt
face-id
android-biometric
0 Answers
Your Answer