Search code examples
androidandroid-studioandroid-6.0-marshmallowandroid-permissionsdalvik

Issue in restrict disabling permissions for android marshmallow and later


I am developing an app that does some admin operations on android devices.

The users of android devices running on marshmallow and later has the ability to disable or enable the permissions for a particular app, and I want to restrict the user from disabling my app's permissions since it is an admin app and it need the permissions to run the app.

Is there anyway to restrict enabling/disabling permissions particularly for apps with device administrator privileges?


Solution

  • You Cannot restrict a user from enabling and/or disabling permissions on devices above Marshmallow.

    The Only thing you can do is just check if the user has disabled the permission then either explain him why your app needs the permissions and if he is still not giving permissions then don't let him enter the app.

    You can check at start of app whether the user has disabled your permission using

     ContextCompat.checkSelfPermission(context, permission);
    

    It will return -1 if the permission is not available.