Determine if biometric hardware is present and the user has enrolled biometrics on Android P

前端 未结 8 1256
半阙折子戏
半阙折子戏 2020-12-13 05:50

I\'m asked to show certain UI elements depending on the presence of biometric hardware. For Android 23-27 I use FingerprintManager#isHardwareDetected() and

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 06:38

    Google finally solved this problem with Android Q

    The android.hardware.biometrics.BiometricManager#canAuthenticate() method can be used to determine if biometrics can be used.

    The method can be used to determine if biometric hardware is present and if the user is enrolled or not.

    Returns BIOMETRIC_ERROR_NONE_ENROLLED if the user does not have any enrolled, or BIOMETRIC_ERROR_HW_UNAVAILABLE if none are currently supported/enabled. Returns BIOMETRIC_SUCCESS if a biometric can currently be used (enrolled and available).

    Hopefully this is added to the androidx.biometric:biometric library, so it can be used on all devices.

    Until then the solution by @algrid works to determine biometrics enrollment.

    And the following can be used to determine, if a fingerprint reader is present.

    Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
                context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
    

提交回复
热议问题