public void get_admin(){ Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "to lock screen"); intent.putExtra("force-locked", DeviceAdminInfo.USES_POLICY_FORCE_LOCK); startActivityForResult(intent, 1); }
private boolean areOtherAdminsSet() { List<ComponentName> admins = dpm.getActiveAdmins(); return Iterables.tryFind(admins, new Predicate<ComponentName>() { @Override public boolean apply(android.content.ComponentName c) { return !cn.equals(c) && dpm.hasGrantedPolicy( c, DeviceAdminInfo.USES_POLICY_LIMIT_PASSWORD); } }).isPresent(); }