如何以编程方式使用密码设置屏幕锁定?

emn*_*mna 11 android lockscreen screen-lock

是否有任何一个可以帮助我设置密码来锁定屏幕的代码?谢谢

Sha*_*hul 22

在您的应用程序中使用此代码,它适用于我:

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();
Run Code Online (Sandbox Code Playgroud)


Max*_*xim 0

http://developer.android.com/guide/topics/admin/device-admin.html

private static DevicePolicyManager dpm =
        (DevicePolicyManager)context
            .getSystemService(Context.DEVICE_POLICY_SERVICE);

private static ComponentName admin = 
        new ComponentName(context, DeviceAdminManager.class);
// add password policies you want
dpm.setPasswordQuality(admin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
dpm.setPasswordMinimumLength(admin, 5);

**boolean result = dpm.resetPassword("newPassword", RESET_PASSWORD_WITHOUT_ENTRY);**
Run Code Online (Sandbox Code Playgroud)