有什么方法可以发现我的设备使用任何类型的屏幕锁定 PIN 码、模式都是安全的吗?

Is there any way to find that my device is secure with any type of screen lock PIN,pattern?

我正在尝试在 android 中构建一个应用程序,该应用程序在启动时会检查设备是否通过任何类型的模式或 pin 安全 我发现 keyguardManager isDeviceSecure() 的这种方法它说 return 如果设备使用 PIN、模式或密码保护,则为真。

您可以使用 DevicePolicyManager 进行检查:

DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);

int passwordQuality = devicePolicyManager.getPasswordQuality(//componentName of device admin here);

if (passwordQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
    // Any password/pincode/swipe is set up.
}

if (devicePolicyManager.isActivePasswordSufficient()) {
    // With this you can check if the device password is sufficient (for example if password quality changes).
}

您可能需要管理员应用程序权限才能执行此操作(不确定)。在这里阅读更多:https://developer.android.com/reference/android/app/admin/DevicePolicyManager.html

编辑:

您还可以扩展 DeviceAdminReceiver,以便在用户更改其 pin 或密码时捕获 Intent。

public class MyDeviceAdminReceiver extends DeviceAdminReceiver {


@Override
    public void onPasswordChanged(Context context, Intent intent) {
        // Display your dialog here if user set any type of password.
    }

}