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

后端 未结 5 1965
死守一世寂寞
死守一世寂寞 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:58

    http://developer.android.com/guide/topics/admin/device-admin.html

    private static DevicePolicyManager dpm =
            (DevicePolicyManager)context
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
    
    private static ComponentName admin = 
            new ComponentName(context, DeviceAdminManager.class);
    // add password policies you want
    dpm.setPasswordQuality(admin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED);
    dpm.setPasswordMinimumLength(admin, 5);
    
    **boolean result = dpm.resetPassword("newPassword", RESET_PASSWORD_WITHOUT_ENTRY);**
    

提交回复
热议问题