0

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

4

1 回答 1

0

您可以使用 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 以便在用户更改其密码或密码时捕获 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.
    }

}
于 2018-04-23T13:22:59.457 回答