我的应用程序包含用于登录的用户身份验证(包括密码/图案、指纹解锁),这取决于设备安全性。我正在使用生物识别管理器来检测设备是否使用BiometricManager支持指纹,并使用isDeviceSecure()检查设备是否受到保护。我需要检测在哪种模式下移动设备受到保护,无论是针/图案、带指纹的针/图案、带面部解锁的针/图案还是所有三种模式(针/图案、面部解锁、指纹)。
问问题
523 次
1 回答
0
这是检测设置的锁类型的代码
将库添加到build.gradle
implementation 'androidx.biometric:biometric:1.0.0-beta01'
并将此代码添加到您的活动中
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean keyguardSecure = keyguardManager.isKeyguardSecure();
Log.e("---", "checkSecurityTypes: keyguardLocked - " + keyguardSecure);//true = pin/pattern
int i = BiometricManager.from(this).canAuthenticate();
Log.e("---", "checkSecurityTypes: " + i);//true 0 = pin/pattern with finger print
switch (i) {
case BiometricManager.BIOMETRIC_SUCCESS:
Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Log.e("MY_APP_TAG", "No biometric features available on this device.");
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
// Prompts the user to create credentials that your app accepts.
break;
}
if (i == 0 && keyguardSecure) {
//fingerprint is always with pin/pattern/password
Log.e("---", "checkSecurityTypes: fingerprint is set with pin/pattern");
} else if (keyguardSecure) {
//true if pin/pattern/password is set
Log.e("---", "checkSecurityTypes: pin/pattern is set");
}
我们无法检测面部类型。有关更多信息,请参阅此链接
于 2020-12-30T06:33:34.867 回答