Face Authentication using androidx Biometric API in Android
Asked Answered
M

4

10

I need to integrate Biometric authentication using Fingerprint and Face authentication. Fingerprint authentication works perfectly but when I set only Face authentication I am getting Biometric not enrolled response from BiometricManager.from(context) method as follows,

val biometricManager = BiometricManager.from(context)
    when(biometricManager.canAuthenticate()){
        BiometricManager.BIOMETRIC_SUCCESS ->{
            Log.e(TAG, "App can authenticate using biometrics.")
        }
        BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->{
            Log.d(TAG, "Hardware not available")
        }
        BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->{
            Log.d(TAG, "Biometric features are currently unavailable.")
        }
        BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED ->{
            Log.d(TAG, "The user hasn't associated any biometric credentials with their account.")
        }
        else ->{
            Log.d(TAG, "Nothing supported")
        }
    }
Mossback answered 28/8, 2020 at 7:38 Comment(6)
Which device and Android version are you testing on? And are you using the AndroidX biometrics library, or the functions built into Android?Persimmon
I am using 'androidx.biometric:biometric:1.0.1' for implementation and testing on One plus 6t having Android 10 OSMossback
This issue is also present on my Galaxy S8 what I use for testing, so this might not be manufacture dependent.Closet
Also tested on LG G6, getting the same result. Not sure if it is manufacture dependent.Mossback
is face registered on device?Selfexplanatory
Yes, I tried setting only Face as wellMossback
M
3

After looking at all the hurdles implementing the biometric for Android, I have chosen not to use BiometricManager.from(context) method to check if Biometric authentication is enabled, instead of that checked if KEYGUARD_SERVICE is enabled and used following prompt info

BiometricPrompt.PromptInfo.Builder().apply {
            setTitle(getString(R.string.title))
            setSubtitle(getString(R.string.sub_title))
            setConfirmationRequired(true)
            setDeviceCredentialAllowed(true)
        }.build()

through which even if only face ID is set and is not supporting the current callbacks, application fallbacks to devices PIN authentication method.

Mossback answered 7/9, 2020 at 5:16 Comment(5)
Did this work, when there are no biometrics( face and fingerprint ) enrolled in device ?Beneficent
Yes, it is working need to add validation keyguardManager.isKeyguardSecureMossback
What is being shown in system prompt when you call authenticate() and there are no biometrics enrolled in device and KEYGUARD_SERVICE is enabled. On which device did you test this ? I suggest you to test in multiple devicesBeneficent
yes, if no biometrics enrolled in the device but KEYGUARD_SERVICE is enabled then app asks for PIN/Pattern lock to authenticate. I have tested the same on Oneplus 6, LG, Samsung J7 which does not have biometric hardware, redmi device as well.Mossback
@VijayPatole Can you please share your code? I'm stuck at some point.Horripilate
B
7

Android Biometric APIs would only work on the devices which have their biometric features (face,fingerprint, iris) compatible with Android Biometric stack. I have a set of devices with Face feature support, among them only few support Android Biometrics.

Beneficent answered 3/9, 2020 at 5:5 Comment(1)
i am using Samsung S10. I can able to authenticate Fingerprint/FaceId. My tablet have only on faceId unable ti show biometric alert it shown hardware not available - error code 12. Code:val authFlag = DEVICE_CREDENTIAL or BIOMETRIC_STRONG promptInfo = BiometricPrompt.PromptInfo.Builder() .setTitle(title).setSubtitle(subtitle).setDescription(description).setAllowedAuthenticators(authFlag).build() I am using this code to shown biometric dialog. if i have only faceId what should i do?Sinistral
M
3

After looking at all the hurdles implementing the biometric for Android, I have chosen not to use BiometricManager.from(context) method to check if Biometric authentication is enabled, instead of that checked if KEYGUARD_SERVICE is enabled and used following prompt info

BiometricPrompt.PromptInfo.Builder().apply {
            setTitle(getString(R.string.title))
            setSubtitle(getString(R.string.sub_title))
            setConfirmationRequired(true)
            setDeviceCredentialAllowed(true)
        }.build()

through which even if only face ID is set and is not supporting the current callbacks, application fallbacks to devices PIN authentication method.

Mossback answered 7/9, 2020 at 5:16 Comment(5)
Did this work, when there are no biometrics( face and fingerprint ) enrolled in device ?Beneficent
Yes, it is working need to add validation keyguardManager.isKeyguardSecureMossback
What is being shown in system prompt when you call authenticate() and there are no biometrics enrolled in device and KEYGUARD_SERVICE is enabled. On which device did you test this ? I suggest you to test in multiple devicesBeneficent
yes, if no biometrics enrolled in the device but KEYGUARD_SERVICE is enabled then app asks for PIN/Pattern lock to authenticate. I have tested the same on Oneplus 6, LG, Samsung J7 which does not have biometric hardware, redmi device as well.Mossback
@VijayPatole Can you please share your code? I'm stuck at some point.Horripilate
N
2

I face the same issue while integrating it into my app When I use

biometricManager.canAuthenticate(BIOMETRIC_STRONG)

to check biometric is available in the device it return BIOMETRIC_ERROR_NONE_ENROLLED and as soon as I change the authentication mode to BIOMETRIC_WEEKit work well I test on Samsung S9 and a few Other devices. Currently is use this biometeric dependency hope it works for you

implementation "androidx.biometric:biometric-ktx:1.2.0-alpha03"
Neotype answered 15/7, 2021 at 14:11 Comment(3)
I changed to BIOMETRIC_WEAK and still the same issue on multiple devicesSubterranean
same problem i have too.. changed dependency and BIOMETRIC_WEAK still not showing Biometric dialog. If ihave only Faceid on my device Samsung Tablet A8Sinistral
@geek919 no i didn't get any solutionSinistral
I
0

Some of the facts I have found while I was working with it. This is based on Biometric API "implementation 'androidx.biometric:biometric:1.0.1'".

  1. Samsung device doesn't support face recognition as it doesn't have a 3D face unlock refer here. The issue is open on the Samsung side, as Samsung had face unlock developed by Samsung itself and not from google OS. But it does support fingerprint scans using biometric manager API.
  2. True face unlocks will only work with Pixel 4(This is based on my testing, not sure other device support but I have tested top-notch device is Samsung including the Note series and Galaxy series, and Motorola series) I only able to use face unlock in Pixel 4.
  3. Samsung is working on it and will be available soon(Not sure when).
  4. Very few application support face unlock as of now as most Android base devices are not from google and 3d based unlock is not available on the manufacturing side.

I have created reference POC for the community to help. The documentation hasn't provided good documentation on biometric change detection. This is pure kotlin code and also detects the biometric change and many functions such as does user enrolled in Bio, does device enroll in Bio, what type of biometric, is the user previously enrolled. Please take a look at this link.

Inhabit answered 5/9, 2020 at 5:4 Comment(13)
Hope you have not validated on Samsung S10 device, Samsung S10 is compatible with Android Biometric stack. Statement "IRIS does not handle by Biometrics" is wrong. If a device has IRIS feature compatible with Android Biometric stack, then it would work. In my devices repo, I have Samsung S10, MI and Pixel 4 device which are compatible with Android Biometrics .Beneficent
Please go through Android Biometric CDD doc source.android.com/compatibility/…Beneficent
Please read my answer I mention Face recognition. All devices are biometric compatible. There are three different versions in S10 if you carefully work. I have work with s10e and still not support, the reason is the patch has been not released by Samsung itself and it as on the waiting list. I have edited my answer which was IRIS related and IRIS is not pure Biometric.Inhabit
Can you explain me why IRIS is not pure Biometric ? I was referring to your statement "Samsung device doesn't support face recognition as it doesn't have a 3D face unlock." I am also trying to understand, what is the dependence of "Face Authentication on 3D face unlock"Beneficent
Face, IRIS and Fingerprint are part of biometrics.You can refer source.android.com/compatibility/…. Question is about face authentication using Android Biometrics . A device fingerprint sensors may compatible with Android Biometrics, It doesnt mean its face sensors too would be supporting Andrid Biometrics.Beneficent
Yes, all three are biometric. Samsung device doesn't support face unlock even with the biometric manager. Can you confirm your s10 support face unlock with biometrics manager API implementation? Please provide me link for your code.Inhabit
There is nothing to do with the code. Yes I confirm Samsung S10 device supports Android Biometrics implementation. It might be you are having older version of Samsung S10 device which dont support Android Biometrics.Beneficent
I am asking face unlock, not biometric support.Inhabit
Yes dude, Face unlock is supported. You can trust me, I have personally tested it. I strongly feel stackoverflow is a platform to help each other and I am just trying to explain you.Beneficent
Please go through this stack #55635312Inhabit
I have gone through it, its a older post. Wait until monday, I wil try to share you video, so that it clears your doubt.Beneficent
Please find image in ibb.co/F8LTBpp, which shows both Face and Fingerprint authentication in Biometric System prompt. Note : zoom in more in the image to observe fingerprint icon.Beneficent
@Shanker: on which device you run the code and is it supporting all the devices having the face and fingerprint authentication?...What in case if the only Face is set for authentication?Mossback

© 2022 - 2024 — McMap. All rights reserved.