Added in API level 29

BiometricManager


open class BiometricManager
kotlin.Any
   ↳ android.hardware.biometrics.BiometricManager

A class that contains biometric utilities. For authentication, see BiometricPrompt.

Summary

Nested classes
abstract

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

open

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

Constants
static Int

The hardware is unavailable.

static Int

The user does not have any biometrics enrolled.

static Int

There is no biometric hardware.

static Int

A security vulnerability has been discovered and the sensor is unavailable until a security update has addressed this issue.

static Long

Returned from BiometricManager#getLastAuthenticationTime(int) when no matching successful authentication has been performed since boot.

static Int

No error detected.

Public methods
open Int

Determine if biometrics can be used.

open Int
canAuthenticate(authenticators: Int)

Determine if any of the provided authenticators can be used.

open Long
getLastAuthenticationTime(authenticators: Int)

Gets the last time the user successfully authenticated using one of the given authenticators.

open BiometricManager.Strings
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 API level 29
static val BIOMETRIC_ERROR_HW_UNAVAILABLE: Int

The hardware is unavailable. Try again later.

Value: 1

BIOMETRIC_ERROR_NONE_ENROLLED

Added in API level 29
static val BIOMETRIC_ERROR_NONE_ENROLLED: Int

The user does not have any biometrics enrolled.

Value: 11

BIOMETRIC_ERROR_NO_HARDWARE

Added in API level 29
static val BIOMETRIC_ERROR_NO_HARDWARE: Int

There is no biometric hardware.

Value: 12

BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED

Added in API level 30
static val BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED: Int

A security vulnerability has been discovered and the sensor is unavailable until a security update has addressed this issue. This error can be received if for example, authentication was requested with Authenticators#BIOMETRIC_STRONG, but the sensor's strength can currently only meet Authenticators#BIOMETRIC_WEAK.

Value: 15

BIOMETRIC_NO_AUTHENTICATION

Added in API level 35
static val BIOMETRIC_NO_AUTHENTICATION: Long

Returned from BiometricManager#getLastAuthenticationTime(int) when no matching successful authentication has been performed since boot.

Value: -1L

BIOMETRIC_SUCCESS

Added in API level 29
static val BIOMETRIC_SUCCESS: Int

No error detected.

Value: 0

Public methods

canAuthenticate

Added in API level 29
Deprecated in API level 30
open fun canAuthenticate(): Int

Deprecated: See canAuthenticate(int).

Determine if biometrics can be used. In other words, determine if BiometricPrompt can be expected to be shown (hardware available, templates enrolled, user-enabled). This is the equivalent of canAuthenticate(int) with Authenticators#BIOMETRIC_WEAK
Requires android.Manifest.permission#USE_BIOMETRIC

Return
Int BIOMETRIC_ERROR_NONE_ENROLLED if the user does not have any strong biometrics enrolled, or BIOMETRIC_ERROR_HW_UNAVAILABLE if none are currently supported/enabled. Returns BIOMETRIC_SUCCESS if a strong biometric can currently be used (enrolled and available). Value is android.hardware.biometrics.BiometricManager#BIOMETRIC_SUCCESS, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_HW_UNAVAILABLE, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_NONE_ENROLLED, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_NO_HARDWARE, or android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED

canAuthenticate

Added in API level 30
open fun canAuthenticate(authenticators: Int): Int

Determine if any of the provided authenticators can be used. In other words, determine if BiometricPrompt can be expected to be shown (hardware available, templates enrolled, user-enabled). For biometric authenticators, determine if the device can currently authenticate with at least the requested strength. For example, invoking this API with Authenticators#BIOMETRIC_WEAK on a device that currently only has Authenticators#BIOMETRIC_STRONG enrolled will return BIOMETRIC_SUCCESS. Invoking this API with Authenticators#DEVICE_CREDENTIAL can be used to determine if the user has a PIN/Pattern/Password set up.
Requires android.Manifest.permission#USE_BIOMETRIC

Parameters
authenticators Int: bit field consisting of constants defined in Authenticators. If multiple authenticators are queried, a logical OR will be applied. For example, if Authenticators#DEVICE_CREDENTIAL | Authenticators#BIOMETRIC_STRONG is queried and only Authenticators#DEVICE_CREDENTIAL is set up, this API will return BIOMETRIC_SUCCESS Value is either 0 or a combination of android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_STRONG, android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_WEAK, android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE, and android.hardware.biometrics.BiometricManager.Authenticators#DEVICE_CREDENTIAL
Return
Int BIOMETRIC_ERROR_NONE_ENROLLED if the user does not have any of the requested authenticators enrolled, or BIOMETRIC_ERROR_HW_UNAVAILABLE if none are currently supported/enabled. Returns BIOMETRIC_SUCCESS if one of the requested authenticators can currently be used (enrolled and available). Value is android.hardware.biometrics.BiometricManager#BIOMETRIC_SUCCESS, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_HW_UNAVAILABLE, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_NONE_ENROLLED, android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_NO_HARDWARE, or android.hardware.biometrics.BiometricManager#BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED

getLastAuthenticationTime

Added in API level 35
open fun getLastAuthenticationTime(authenticators: Int): Long

Gets the last time the user successfully authenticated using one of the given authenticators. The returned value is time in SystemClock.elapsedRealtime() (time since boot, including sleep).

BiometricManager#BIOMETRIC_NO_AUTHENTICATION is returned in the case where there has been no successful authentication using any of the given authenticators since boot.

Currently, only Authenticators#DEVICE_CREDENTIAL and Authenticators#BIOMETRIC_STRONG are accepted. IllegalArgumentException will be thrown if authenticators contains other authenticator types.

Note that this may return successful authentication times even if the device is currently locked. You may use KeyguardManager#isDeviceLocked() to determine if the device is unlocked or not. Additionally, this method may return valid times for an authentication method that is no longer available. For instance, if the user unlocked the device with a Authenticators#BIOMETRIC_STRONG authenticator but then deleted that authenticator (e.g., fingerprint data), this method will still return the time of that unlock for Authenticators#BIOMETRIC_STRONG if it is the most recent successful event. The caveat is that BiometricManager#BIOMETRIC_NO_AUTHENTICATION will be returned if the device no longer has a secure lock screen at all, even if there were successful authentications performed before the lock screen was made insecure.
Requires android.Manifest.permission#USE_BIOMETRIC
Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime() time base.

Parameters
authenticators Int: bit field consisting of constants defined in Authenticators. Value is either 0 or a combination of android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_STRONG, android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_WEAK, android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE, and android.hardware.biometrics.BiometricManager.Authenticators#DEVICE_CREDENTIAL
Return
Long the time of last authentication or BiometricManager#BIOMETRIC_NO_AUTHENTICATION Value is a non-negative timestamp in the android.os.SystemClock#elapsedRealtime() time base.
Exceptions
java.lang.IllegalArgumentException if authenticators contains values other than Authenticators#DEVICE_CREDENTIAL and Authenticators#BIOMETRIC_STRONG or is 0.

getStrings

Added in API level 31
open 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.
Requires android.Manifest.permission#USE_BIOMETRIC

Parameters
authenticators Int: A bit field representing the types of Authenticators that may be used for authentication. Value is either 0 or a combination of android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_STRONG, android.hardware.biometrics.BiometricManager.Authenticators#BIOMETRIC_WEAK, android.hardware.biometrics.BiometricManager.Authenticators.BIOMETRIC_CONVENIENCE, and android.hardware.biometrics.BiometricManager.Authenticators#DEVICE_CREDENTIAL
Return
BiometricManager.Strings A Strings collection for the given allowed authenticator types. This value cannot be null.