Created
July 17, 2016 12:02
-
-
Save Egorand/b1e4073c5261f996bfd5509f495b5a85 to your computer and use it in GitHub Desktop.
android-testing-runtime-permissions-on-grant-permission
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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