How to programmatically disable the screen lock password.

My script creates a password and locks the phone, but if I try to change the password to a
space, it does not work.

My lock script:

DevicePolicyManager deviceManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
                  ComponentName compName = new ComponentName(MessageService.this, LockAdmin.class);  

                  boolean active = deviceManager.isAdminActive(compName);  

                  if (active) { 
                      deviceManager.setPasswordQuality(compName,DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
                      deviceManager.setPasswordMinimumLength(compName, 5);

                      boolean result = deviceManager.resetPassword("blablabla", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);
                  }

So my question is: how can I change the password to empty or how can I change the lock pattern to "none"?

+4
source share
1 answer

After 2 minutes I tried

deviceManager.setPasswordMinimumLength(compName, 0);
boolean result = deviceManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY);

And it works like a charm.

+5
source

All Articles