Skip to content

Instantly share code, notes, and snippets.

@Egorand
Created July 17, 2016 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Egorand/b1e4073c5261f996bfd5509f495b5a85 to your computer and use it in GitHub Desktop.
Save Egorand/b1e4073c5261f996bfd5509f495b5a85 to your computer and use it in GitHub Desktop.
android-testing-runtime-permissions-on-grant-permission
public void onGrantPermission(View view) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS},
REQ_CODE_PERMISSIONS_READ_CONTACTS);
} else {
goToSettings();
}
}
private void goToSettings() {
Uri uri = Uri.fromParts("package", getPackageName(), null);
Intent settingsIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, uri);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(settingsIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment