BiometricManager


class BiometricManager


A class that provides system information related to biometrics (e.g. fingerprint, face, etc.).

On devices running Android 10 (API 29) and above, this will query the framework's version of android.hardware.biometrics.BiometricManager. On Android 9.0 (API 28) and prior versions, this will query androidx.core.hardware.fingerprint.FingerprintManagerCompat.

See also
BiometricPrompt

To prompt the user to authenticate with their biometric.

Summary

Nested types

Types of authenticators, defined at a level of granularity supported by BiometricManager and BiometricPrompt.

Provides localized strings for an application that uses BiometricPrompt to authenticate the user.

Constants

const Int

The user can't authenticate because the hardware is unavailable.

const Int

The user can't authenticate because no biometric or device credential is enrolled.

const Int

The user can't authenticate because there is no suitable hardware (e.g. no biometric sensor or no keyguard).

const Int

The user can't authenticate because a security vulnerability has been discovered with one or more hardware sensors.

const Int

The user can't authenticate because the specified options are incompatible with the current Android version.

const Int

Unable to determine whether the user can authenticate.

const Int

The user can successfully authenticate.

Public functions

Int

This function is deprecated.

Use canAuthenticate instead.

Int
canAuthenticate(authenticators: Int)

Checks if the user can authenticate with an authenticator that meets the given requirements.

java-static BiometricManager
from(context: Context)

Creates a BiometricManager instance from the given context.

BiometricManager.Strings?
@RequiresPermission(value = Manifest.permission.USE_BIOMETRIC)
getStrings(authenticators: Int)

Produces an instance of the Strings class, which provides localized strings for an application, given a set of allowed authenticator types.

Constants

BIOMETRIC_ERROR_HW_UNAVAILABLE

Added in 1.0.0
const val BIOMETRIC_ERROR_HW_UNAVAILABLE = 1: Int

The user can't authenticate because the hardware is unavailable. Try again later.

BIOMETRIC_ERROR_NONE_ENROLLED

Added in 1.0.0
const val BIOMETRIC_ERROR_NONE_ENROLLED = 11: Int

The user can't authenticate because no biometric or device credential is enrolled.

BIOMETRIC_ERROR_NO_HARDWARE

Added in 1.0.0
const val BIOMETRIC_ERROR_NO_HARDWARE = 12: Int

The user can't authenticate because there is no suitable hardware (e.g. no biometric sensor or no keyguard).

BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED

Added in 1.1.0
const val BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED = 15: Int

The user can't authenticate because a security vulnerability has been discovered with one or more hardware sensors. The affected sensor(s) are unavailable until a security update has addressed the issue.

BIOMETRIC_ERROR_UNSUPPORTED

Added in 1.1.0
const val BIOMETRIC_ERROR_UNSUPPORTED = -2: Int

The user can't authenticate because the specified options are incompatible with the current Android version.

BIOMETRIC_STATUS_UNKNOWN

Added in 1.1.0
const val BIOMETRIC_STATUS_UNKNOWN = -1: Int

Unable to determine whether the user can authenticate.

This status code may be returned on older Android versions due to partial incompatibility with a newer API. Applications that wish to enable biometric authentication on affected devices may still call BiometricPrompt#authenticate() after receiving this status code but should be prepared to handle possible errors.

BIOMETRIC_SUCCESS

Added in 1.0.0
const val BIOMETRIC_SUCCESS = 0: Int

The user can successfully authenticate.

Public functions

canAuthenticate

Added in 1.0.0
Deprecated in 1.1.0
fun canAuthenticate(): Int

Checks if the user can authenticate with biometrics. This requires at least one biometric sensor to be present, enrolled, and available on the device.

Returns
Int

BIOMETRIC_SUCCESS if the user can authenticate with biometrics. Otherwise, returns an error code indicating why the user can't authenticate, or BIOMETRIC_STATUS_UNKNOWN if it is unknown whether the user can authenticate.

canAuthenticate

Added in 1.1.0
fun canAuthenticate(authenticators: Int): Int

Checks if the user can authenticate with an authenticator that meets the given requirements. This requires at least one of the specified authenticators to be present, enrolled, and available on the device.

Note that not all combinations of authenticator types are supported prior to Android 11 (API 30). Specifically, DEVICE_CREDENTIAL alone is unsupported prior to API 30, and BIOMETRIC_STRONG | DEVICE_CREDENTIAL is unsupported on API 28-29. Developers that wish to check for the presence of a PIN, pattern, or password on these versions should instead use isDeviceSecure.

Parameters
authenticators: Int

A bit field representing the types of Authenticators that may be used for authentication.

Returns
Int

BIOMETRIC_SUCCESS if the user can authenticate with an allowed authenticator. Otherwise, returns BIOMETRIC_STATUS_UNKNOWN or an error code indicating why the user can't authenticate.

from

Added in 1.0.0
java-static fun from(context: Context): BiometricManager

Creates a BiometricManager instance from the given context.

Parameters
context: Context

The application or activity context.

Returns
BiometricManager

An instance of BiometricManager.

getStrings

Added in 1.4.0-alpha02
@RequiresPermission(value = Manifest.permission.USE_BIOMETRIC)
fun getStrings(authenticators: Int): BiometricManager.Strings?

Produces an instance of the Strings class, which provides localized strings for an application, given a set of allowed authenticator types.

Parameters
authenticators: Int

A bit field representing the types of Authenticators that may be used for authentication.

Returns
BiometricManager.Strings?

A Strings collection for the given allowed authenticator types.