我的应用程序包含登录的用户身份验证(包括引脚/图案、指纹解锁),这取决于设备的安全性。我使用生物识别管理器来检测设备是否具有使用BiometricManager的指纹支持,并检查设备是否使用isDeviceSecure().进行安全保护。我需要检测哪种模式的移动设备是用引脚/图案、带指纹的引脚/图案、带面部解锁的引脚/图案还是这三种模式(针/图案、脸解锁、指纹)。
发布于 2020-12-30 06:33:34
下面是用来检测设置了什么锁类型的代码
向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");
}
我们找不到脸的类型。有关更多信息,请参见此link
https://stackoverflow.com/questions/65474598
复制相似问题