Last active
August 22, 2018 09:42
-
-
Save ssaurel/66c22ccdb45a5a3b3853116c511bd786 to your computer and use it in GitHub Desktop.
onRequestPermissionsResult callback for the GPS Tutorial on the SSaurel's Channel
This file contains 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
@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