Check if devices has biometric enabled with androidx biometric prompt

AndroidX Biometric beta01 added BiometricManager.canAuthenticate()

Use the following dependency line in your app module's build.gradle file.

implementation 'androidx.biometric:biometric:1.0.0-beta01'

Then you can do the following to check if any biometrics are ready for use on the device.

BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS

On Android 6 to 9 this only supports fingerprints. On 10 and above it will support any biometric (eg. face, iris).


FingerPrintManager has the data regarding fingerpint authentication only, hence it has hasEnrolledFringers(). But BiometricPrompt is used for face unlock, finerprint, iris. It's like a common manager class. Google has added canAuthenticate which supports from Android Q. But you can check it for lower API using

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
       val hasBiometricFeature :Boolean = context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)

Anyway, Google has also added it to androidx components androidx.biometric:biometric

implementation 'androidx.biometric:biometric:1.0.0-alpha04'

uses permission

<uses-permission android:name="android.permission.USE_BIOMETRIC" />

on `AuthenticationCallback'

public void onAuthenticationError(int errorCode, CharSequence errString) {}

you can check the error codes with the ones

/**
 * The user does not have any biometrics enrolled.
 */
int BIOMETRIC_ERROR_NO_BIOMETRICS = 11;

If you are using compileSdkVersion 29 and buildToolsVersion "29.0.1". You can use a native check method.

I wrote this function for Kotlin:

 fun checkForBiometrics() : Boolean {
    Log.d(TAG, "checkForBiometrics started")
    var canAuthenticate = true
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (Build.VERSION.SDK_INT < 29) {
            val keyguardManager : KeyguardManager = applicationContext.getSystemService(KEYGUARD_SERVICE) as KeyguardManager
            val packageManager : PackageManager   = applicationContext.packageManager
            if(!packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
                Log.w(TAG, "checkForBiometrics, Fingerprint Sensor not supported")
                canAuthenticate = false
            }
            if (!keyguardManager.isKeyguardSecure) {
                Log.w(TAG, "checkForBiometrics, Lock screen security not enabled in Settings")
                canAuthenticate = false
            }
        } else {
            val biometricManager : BiometricManager = this.getSystemService(BiometricManager::class.java)
            if(biometricManager.canAuthenticate() != BiometricManager.BIOMETRIC_SUCCESS){
                Log.w(TAG, "checkForBiometrics, biometrics not supported")
                canAuthenticate = false
            }
        }
    }else{
        canAuthenticate = false
    }
    Log.d(TAG, "checkForBiometrics ended, canAuthenticate=$canAuthenticate ")
    return canAuthenticate
}

Additional, you have to implement on you app gradle file as dependecy:

implementation 'androidx.biometric:biometric:1.0.0-alpha04'

and also use the newest build tools:

compileSdkVersion 29
buildToolsVersion "29.0.1"