Skip to content

Instantly share code, notes, and snippets.

@GursheeshSingh
Created April 13, 2019 20:20
Show Gist options
  • Save GursheeshSingh/c788cf601c1e8fd25ff36bc93496a14e to your computer and use it in GitHub Desktop.
Save GursheeshSingh/c788cf601c1e8fd25ff36bc93496a14e to your computer and use it in GitHub Desktop.
If user selected Don't ask again option
//If User was asked permission before and denied
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Permission needed");
alertDialogBuilder.setMessage("Storage permission needed for accessing photos");
alertDialogBuilder.setPositiveButton("Open Setting", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", MainActivity.this.getPackageName(),
null);
intent.setData(uri);
MainActivity.this.startActivity(intent);
}
});
alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Log.d(TAG, "onClick: Cancelling");
}
});
AlertDialog dialog = alertDialogBuilder.create();
dialog.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment