Android DevicePolicyManager policies to setup password validations

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 05:46:19

问题


I am using DevicePolicyManager to setup password policies , i have used the below and they are working fine

DevicePolicyManager devicePolicyManager;
    ComponentName demoDeviceAdmin;

// Initialize Device Policy Manager service and our receiver class
                devicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
                demoDeviceAdmin = new ComponentName(this, AdminReceiver.class);

devicePolicyManager.lockNow();
devicePolicyManager.wipeData(0);

but when i used the below methods of DevicePolicyManager to create a password validations like below they are not working

devicePolicyManager.setPasswordMinimumLetters(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumLowerCase(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumNumeric(demoDeviceAdmin, 2);
            devicePolicyManager.setPasswordMinimumUpperCase(demoDeviceAdmin, 2);
devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 10);

only the below method is working

devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, 10);

please anyone guide me what i am doing wrong ?

public class AdminReceiver extends DeviceAdminReceiver {

    @Override
    public void onEnabled(Context context, Intent intent) {
        super.onEnabled(context, intent);
         showToast(context, "---onEnabled----");
         Log.e("------onEnabled--------", "------onEnabled--------");
    }

    @Override
    public CharSequence onDisableRequested(Context context, Intent intent) {
        // TODO Auto-generated method stub
         showToast(context, "---onDisableRequested----");
         Log.e("------onDisableRequested--------", "------onDisableRequested--------");
        return super.onDisableRequested(context, intent);
    }



    @Override
    public void onPasswordExpiring(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordExpiring(context, intent);
        showToast(context, "----onPasswordExpiring---");
    }

    @Override
    public void onPasswordFailed(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordFailed(context, intent);
        showToast(context, "----onPasswordFailed---");
    }

    @Override
    public void onPasswordSucceeded(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPasswordSucceeded(context, intent);
        showToast(context, "----onPasswordSucceeded---");
    }


    void showToast(Context context, String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onDisabled(Context context, Intent intent) {
        showToast(context, "onDisabled");
        Log.e("------onDisabled--------", "------onDisabled--------");
    }

    @Override
    public void onPasswordChanged(Context context, Intent intent) {
        showToast(context, "----onPasswordChanged---");
    }

}

来源:https://stackoverflow.com/questions/39489830/android-devicepolicymanager-policies-to-setup-password-validations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!