android - 检测设备是用针锁或面部锁的指纹锁保护的吗?

标签 android android-fingerprint-api android-biometric-prompt android-biometric

我的应用程序包含用于登录的用户身份验证(包括密码/图案、指纹解锁),这取决于设备安全性。我正在使用生物识别管理器来检测设备是否支持使用 的指纹。生物识别管理器 并使用 检查设备是否安全isDeviceSecure() .我需要检测在哪种模式下移动设备是安全的,无论是带有针脚/图案、带指纹的针/图案、带面部解锁的针/图案还是所有三种模式(针/图案、面部解锁、指纹)。

最佳答案

这是检测设置的锁类型的代码
将库添加到 build.gradle

implementation 'androidx.biometric:biometric:1.0.0-beta01'
并将此代码添加到您的 Activity 中
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

关于android - 检测设备是用针锁或面部锁的指纹锁保护的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65474598/

相关文章:

java - AndroidPlot: XYPlot 如何制作带圆角的条形图

android - 第二次加载google visualization api

android - Firebase无法正常运行Android Studio 3.0.1 [com.android.support:support-core-utils:27.1.0]

android - Android 6 上未显示生物识别提示

android - 如何将用户指纹与登录信息相关联

android - 获取在 Youtube android 应用程序中运行的视频的 URL

java - Android指纹取消信号FINGERPRINT_ACQUIRED_TOO_FAST

android - 是否可以在Android的指纹API中识别多个手指?

android - 无法为任务 ':app:javaPreCompileProductionDebug' 捕获输入文件的指纹

android - BiometricPrompt 执行器和/或回调为空