Search code examples
javaandroidlockingdevice-managerdevice-policy-manager

How to disable screen lock password programmatically.


My script creates password and locks the phone, but if I try to change password to
blank, it fails.

My locking 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 could I change password to blank or how could I change locking pattern to "none"?


Solution

  • 2 minutes later I have tried,

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

    And it works like a charm.