Skip to content

Instantly share code, notes, and snippets.

@ssaurel
Last active August 22, 2018 09:42
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 ssaurel/66c22ccdb45a5a3b3853116c511bd786 to your computer and use it in GitHub Desktop.
Save ssaurel/66c22ccdb45a5a3b3853116c511bd786 to your computer and use it in GitHub Desktop.
onRequestPermissionsResult callback for the GPS Tutorial on the SSaurel's Channel
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch(requestCode) {
case ALL_PERMISSIONS_RESULT:
for (String perm : permissionsToRequest) {
if (!hasPermission(perm)) {
permissionsRejected.add(perm);
}
}
if (permissionsRejected.size() > 0) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (shouldShowRequestPermissionRationale(permissionsRejected.get(0))) {
new AlertDialog.Builder(MainActivity.this).
setMessage("These permissions are mandatory to get your location. You need to allow them.").
setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(permissionsRejected.
toArray(new String[permissionsRejected.size()]), ALL_PERMISSIONS_RESULT);
}
}
}).setNegativeButton("Cancel", null).create().show();
return;
}
}
} else {
if (googleApiClient != null) {
googleApiClient.connect();
}
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment