Source:
public static void requestPermission(final AppCompatActivity activity, final String permission, final int permissionRequestCode, final String dialogMessageRetry, final String messageNeverAskAgain, final String permissionDeniedStatus) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { new MaterialDialog.Builder().init(activity) .setTitle(R.string.permission_denied) .setMessage(dialogMessageRetry) .setPositiveButton(R.string.dialog_action_i_am_sure) .setNegativeButton(R.string.dialog_action_re_try, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionRequestCode); } }) .createMaterialDialog() .show(); } else { if (PrefManager.getBoolean(permissionDeniedStatus, true)) { PrefManager.putBoolean(permissionDeniedStatus, false); ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionRequestCode); } else { new MaterialDialog.Builder().init(activity) .setMessage(messageNeverAskAgain) .setNegativeButton(R.string.dialog_action_cancel) .setPositiveButton(R.string.dialog_action_app_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings .ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(activity.getResources().getString( R.string.package_name), activity.getPackageName() , null); intent.setData(uri); try { activity.startActivityForResult(intent, Constants.REQUEST_PERMISSION_SETTING); } catch (ActivityNotFoundException exception) { Toast.makeText(activity, R.string.app_settings_activity_failed , Toast.LENGTH_SHORT) .show(); Log.d("MifosApp", "cant find activity with name"); } } }) .createMaterialDialog() .show(); } } }

Target:
public static void requestPermission(final AppCompatActivity activity, final String permission, final int permissionRequestCode, final String dialogMessageRetry, final String messageNeverAskAgain, final String permissionDeniedStatus) { if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) { new MaterialDialog.Builder().init(activity) .setTitle(R.string.permission_denied) .setMessage(dialogMessageRetry) .setPositiveButton(R.string.dialog_action_i_am_sure) .setNegativeButton(R.string.dialog_action_re_try, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionRequestCode); } }) .createMaterialDialog() .show(); } else { if (PrefManager.getBoolean(permissionDeniedStatus, true)) { PrefManager.putBoolean(permissionDeniedStatus, false); ActivityCompat.requestPermissions(activity, new String[]{permission}, permissionRequestCode); } else { new MaterialDialog.Builder().init(activity) .setMessage(messageNeverAskAgain) .setNegativeButton(R.string.dialog_action_cancel) .setPositiveButton(R.string.dialog_action_app_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings .ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(activity.getResources().getString( R.string.package_name), activity.getPackageName() , null); intent.setData(uri); PackageManager packageManager = activity .getPackageManager(); if (intent.resolveActivity(packageManager) != null) { activity.startActivityForResult(intent, Constants.REQUEST_PERMISSION_SETTING); } else { Toast.makeText(activity, R.string.app_settings_activity_failed , Toast.LENGTH_SHORT) .show(); Log.d(TAG, "cant find activity with name"); } } }) .createMaterialDialog() .show(); } } }