如何通过编程禁用屏幕锁定密码。

4

我的脚本可以创建密码并锁定手机,但是如果我试图将密码更改为空白,它会失败。

我的锁定脚本:

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);
                  }

所以我的问题是,我如何将密码更改为空白,或者如何将锁定模式更改为“无”?
1个回答

5

两分钟后,我尝试了一下,

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

它的运作效果非常好。


1
无法在Nougat设备上运行,会抛出安全异常并崩溃。 - Mohd Saquib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接