确定哪些类型的生物识别硬件可用Android

时间:2020-06-26 20:01:56

标签: android android-studio kotlin android-biometric-prompt android-biometric

我正在使用Kotlin设置生物特征登录。我可以使用它,但是我想根据可用的硬件(即)切换显示哪个图标。显示用于视网膜扫描的视网膜扫描仪图标,用于指纹扫描的指纹等。 到目前为止,在研究文档时,我还没有找到一种方法来确定这一点,而Google机器并不是很有用。

类似的东西

when (biometricManager.biometricType) {
face -> {}
fingerprint -> {}
retinaScanner -> {}
}

太棒了。是否存在?

1 个答案:

答案 0 :(得分:0)

我知道了,您使用了程序包管理器。

enum class BiometricType {
            Iris, Fingerprint, Face, None
        }

fun biometricType(context: Context): BiometricType {
        return when {
            context.applicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_FACE) -> BiometricType.Face
            context.applicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) -> BiometricType.Fingerprint
            context.applicationContext.packageManager.hasSystemFeature(PackageManager.FEATURE_IRIS) -> BiometricType.Iris
            else -> BiometricType.None
        }
    }

希望这可以帮助将来的其他人