如何以编程方式禁用屏幕锁定密码。

问题描述:

我的脚本创建密码并锁定手机,但如果我尝试将密码更改为
为空,则会失败。如何以编程方式禁用屏幕锁定密码。

我锁定脚本:

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

所以我的问题是,我怎么能更改密码设置为空或如何能更改锁定模式为“无”?

2分钟后我都试过了,

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

它就像一个魅力。

+0

不适用于牛轧糖设备,抛出安全异常和崩溃 –