Skip to content

Instantly share code, notes, and snippets.

@hitherejoe
Last active September 2, 2016 22:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitherejoe/42d0925037d4556e2420 to your computer and use it in GitHub Desktop.
Save hitherejoe/42d0925037d4556e2420 to your computer and use it in GitHub Desktop.
private void requestMultiplePermissions() {
String locationPermission = Manifest.permission.ACCESS_FINE_LOCATION;
String calendarPermission = Manifest.permission.WRITE_CALENDAR;
int hasLocPermission = checkSelfPermission(locationPermission);
int hasCalPermission = checkSelfPermission(calendarPermission);
List<String> permissions = new ArrayList<String>();
if (hasLocPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(locationPermission);
}
if (hasCalPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(calendarPermission);
}
if (!permissions.isEmpty()) {
String[] params = permissions.toArray(new String[permissions.size()]);
requestPermissions(params, REQUEST_PERMISSIONS);
} else {
// We already have permission, so handle as normal
}
}
@prolificcoder
Copy link

Do you have the full code somewhere on github? I trying to figure out how to invoke https://medium.com/exploring-android/handling-android-runtime-permissions-in-ui-tests-981f9dc11a4e#.zew5w8sjg this method and also implmentations of checkSelfPermission and requestPermissions

@esmeel
Copy link

esmeel commented Sep 2, 2016

  1. in this case, do I need to override onRequestPermissionsResult() ??
    and what will I check there? (all the permissions requested)?
  2. I try it(the code above) I just get one dialogue, thus one request!! when allow I wait for another and not get it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment