Skip to content Skip to sidebar Skip to footer

How To Disallow User From Changing Permissions On A Device Owner App?

Note : The application by default cannot be uninstalled as it is a device owner app with device admin privileges and all permissions are granted by default. But it is possible for

Solution 1:

This solved it for me :

targetSdkVersion should be 23 or above for this to work.

DevicePolicyManager dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

ComponentName mDeviceAdmin = new ComponentName(this, AdminReceiver.class);

    try {
                String[] permissions = context.getPackageManager().getPackageInfo(context.getPackageName(),PackageManager.GET_PERMISSIONS).requestedPermissions;
                for (String permission : permissions) {
                    boolean success = dpm.setPermissionGrantState(mDeviceAdmin,
                            getPackageName(), permission, PERMISSION_GRANT_STATE_GRANTED);
                    if (!success) {
                        Log.e(TAG, "Failed to auto grant permission to self: " + permission);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

PERMISSION_GRANT_STATE_GRANTED : The permission is granted to the app and the user cannot manage the permission through the UI.

PERMISSION_GRANT_STATE_DENIED : The permission is denied to the app and the user cannot manage the permission through the UI.

PERMISSION_GRANT_STATE_DEFAULT : The user can manage the permission through the UI.

Post a Comment for "How To Disallow User From Changing Permissions On A Device Owner App?"