Skip to content

Instantly share code, notes, and snippets.

@DanishAmjad12
Last active October 24, 2018 05:33
Show Gist options
  • Save DanishAmjad12/598655deae6130c91cb6cc95a541945f to your computer and use it in GitHub Desktop.
Save DanishAmjad12/598655deae6130c91cb6cc95a541945f to your computer and use it in GitHub Desktop.
result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
@Override
public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
try {
LocationSettingsResponse response = task.getResult(ApiException.class);
// All location settings are satisfied. The client can initialize location
// requests here.
setupLocationListener();
} catch (ApiException exception) {
switch (exception.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Location settings are not satisfied. But could be fixed by showing the
// user a dialog.
try {
// Cast to a resolvable exception.
ResolvableApiException resolvable = (ResolvableApiException) exception;
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
resolvable.startResolutionForResult(
Activity.this, IntentConstant.REQ_LOCATION_SETTINGS);
} catch (IntentSender.SendIntentException | ClassCastException e) {
// Ignore the error.
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Location settings are not satisfied. However, we have no way to fix the
// settings so we won't show the dialog.
break;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment