How can i set up screen lock with a password programmatically?

后端 未结 5 1975
死守一世寂寞
死守一世寂寞 2020-11-28 10:30

Is there any one that can help me with a code to set a password to lock the screen ? thx

5条回答
  •  野性不改
    2020-11-28 10:39

    Use this code in your App, it works for me:

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

提交回复
热议问题