lidox lidox - 1 year ago 73
Android Question

How to change denied/granted permission in Android M?

How can I give the user a chance to change his permissions in the App,
which he has already set to granted/denied?

Let's say a user denied a permission. Later he want's to grant this permission.
Is it possible? How can I do that?

Answer Source

In case user has denied the permission you can check for the permission and if he also has checked never show again, in that case you can open your own dialog explaining the need of that permission for your app and from that dialog you can take the user to the app settings where he can allow the permission if he wanted.

public static void checkPermissionForExternalStorage(final Context mContext) {

    if (Build.VERSION.SDK_INT >= 23) {

        int writeExternalStorage = ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (writeExternalStorage != PackageManager.PERMISSION_GRANTED) {

            ActivityCompat.requestPermissions((Activity) mContext, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE_ASK_PERMISSIONS_FOR_STORAGE);

        //Do your stuff

    } else {

       //Do your stuff

 public static void startInstalledAppDetailsActivity(Context mContext) {

    Intent i = new Intent();
    i.setData(Uri.parse("package:" + mContext.getPackageName()));

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

    switch (requestCode) {

            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //Do your stuff
            } else {
                // Permission Denied

                if (!ActivityCompat.shouldShowRequestPermissionRationale((Activity) mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    showMessageOKCancel("The app was not allowed to write to your storage. Hence, it cannot function properly. Please consider granting it this permission. Tap Settings > Permissions, and turn Storage on.",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    startInstalledAppDetailsActivity((Activity) mContext);

                Toast.makeText( mContext, "Write to external storage permission request denied.", Toast.LENGTH_SHORT).show();
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);