Reputation: 7973
How can I deny granted permission programmatically in Android. I can Add the run time permission, Is there any way to deny the permissions on button click.
Upvotes: 2
Views: 2560
Reputation: 28268
You can't either grant or deny a permission programmatically in this way (pseudo code):
if(buttonpressed){
getPermission(PERMISSiON.WRITE_EXTERNAL_STORAGE).deny();
}
And similarly, you cannot allow a permission like this. You can, however direct the user to the permission screen and before doing that prompt the user to enable/disable the permission:
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivity(intent);
Please note that this only works if you target API 23+, and only works with dangerous permissions. You cannot disable the normal permissions (like INTERNET)
Upvotes: 2