在安卓系统中,BiometricPrompt prompt已经取代了过时的FingerprintManager。FingerPrintManager有两个函数hasEnrolledFingerprints()和isHardwareDetected(),用于检查设备是否支持指纹,以及用户是否注册了指纹身份验证。
对于新的BiometricPrompt,在不尝试提示BiometricPrompt的情况下,似乎没有任何功能来检查这一点。调用BiometricPrompt.AuthenticationCallback.onAuthenticationError(时会显示错误代码,指示设备是否支持生物识别以及用户是否注册了生物识别身份验证。
因此,只有在尝试从用户进行身份验证时,我才能获得此信息。有没有一种方法可以在不尝试提示身份验证的情况下检查设备是否支持生物特征识别以及用户是否已注册它们?
发布于 2019-09-10 02:29:18
AndroidX Biometric beta01添加了BiometricManager.canAuthenticate(int)) (以前称为BiometricManager.canAuthenticate()
在应用程序模块的build.gradle文件中使用以下依赖项行。
implementation 'androidx.biometric:biometric:1.1.0'然后,您可以执行以下操作来检查是否有任何生物特征可以在设备上使用。
BiometricManager.from(context).canAuthenticate(int) == BiometricManager.BIOMETRIC_SUCCESS在Android 6到9上,这只支持指纹。在10和更高版本上,它将支持任何生物特征(例如,脸,虹膜)。
发布于 2019-05-28 16:58:48
FingerPrintManager只有关于指纹认证的数据,因此它有hasEnrolledFringers()。但是BiometricPrompt是用来解锁脸部,精细打印,虹膜的。它就像一个普通的管理器类。谷歌已经添加了canAuthenticate,它支持安卓Q。但你可以使用以下命令查看它的较低接口
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
val hasBiometricFeature :Boolean = context.packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)无论如何,谷歌也已经将它添加到了androidx组件androidx.biometric:biometric中
implementation 'androidx.biometric:biometric:1.0.0-alpha04'使用权限
<uses-permission android:name="android.permission.USE_BIOMETRIC" />关于` `AuthenticationCallback‘
public void onAuthenticationError(int errorCode, CharSequence errString) {}您可以将错误代码与错误代码进行核对
/**
* The user does not have any biometrics enrolled.
*/
int BIOMETRIC_ERROR_NO_BIOMETRICS = 11;发布于 2019-08-22 07:15:11
如果您使用的是compileSdkVersion 29和buildToolsVersion "29.0.1“。您可以使用本机检查方法。
我为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
}另外,你必须在你的app gradle文件中实现依赖关系:
implementation 'androidx.biometric:biometric:1.0.0-alpha04'并使用最新的构建工具:
compileSdkVersion 29
buildToolsVersion "29.0.1"https://stackoverflow.com/questions/56337875
复制相似问题