如何设置屏幕锁定使用密码编程?如何设置、屏幕、密码

2023-09-12 00:52:38 作者:桃李春风

有没有一个可以帮我一个code设置密码锁定屏幕? THX

Is there any one that can help me with a code to set a password to lock the screen ? thx

推荐答案

使用这种code在你的应用程序,它为我工作:

Use this code in your App, it works for me:

DevicePolicyManager devicePolicyManager =   
             DevicePolicyManager.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName demoDeviceAdmin = new ComponentName(this, name of activity);

devicePolicyManager.setPasswordQuality(
             demoDeviceAdmin,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 5);

boolean result = devicePolicyManager.resetPassword("123456",
             DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

Toast.makeText(this, 
             "button_lock_password_device..."+result, 
             Toast.LENGTH_LONG).show();