我的应用程序包含登录的用户身份验证(包括 pin/图案、指纹解锁),这取决于设备安全性。我正在使用生物识别管理器来检测设备是否支持指纹生物识别管理器并检查设备是否安全使用isDeviceSecure()。我需要检测移动设备在哪种模式下受到保护,无论是使用引脚/图案、使用指纹的引脚/图案、使用面部解锁的引脚/图案还是所有三种模式(引脚/图案、面部解锁、指纹)。
这是检测设置的锁定类型的代码
添加库到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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)