Updating to Google Play Services v7.0+, and based in this sample for LocationUpdates in Android, I have the following code to connect to the LocationServices.SettingsApi
and check if user has everything OK for the Application receive the location updates.
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
mLocationSettingsRequest = builder.build();
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
Where this
is the following callback:
@Override
public void onResult(LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
Intent resolutionIntent;
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
// Everything is OK, starting request location updates
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
// Seems the user need to change setting to enable locations updates, call startResolutionForResult(Activity, REQUEST_CODE)
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// Error, cannot retrieve location updates.
break;
}
}
The SUCCESS
it OK to reproduce, just keep GPS enabled.
The RESOLUTION_REQUIRED
is also OK to reproduce, only disable GPS.
The SETTINGS_CHANGE_UNAVAILABLE
is the deal: If user select "NEVER" when the step RESOLUTION_REQUIRED
is executed, the result will come with this status always.
Did the Google Play Services has a option to reset programmatically the flag when user select the "NEVER" option?
I know that "NEVER" seems to be "Really, don't ask me again!!!", but I thinking to create a option in case the user change his mind, of course, if this can be possible.
In this case I'll be able to receive the status RESOLUTION_REQUIRED
again and ask to user to accept the LocationUpdates when the app is executed next time.
LocationSettingsRequest.Builder has a method setAlwaysShow that changes the buttons of the dialog:
Always show the dialog, without the "Never" option to suppress future dialogs from this app. When this flag is set to true, the dialog will show up if the location settings do not satisfy the request, even if a user has previously chosen "Never". NOTE: Only use this method if your dialog is the result of an explicit user-initiated action that requires location to proceed. Canceling this dialog should also cancel the initiated action.
Instead the default Yes, Not now and Never buttons if you call setAlwaysShow(true);
you will have only Yes and No, so the user won't choose Never and you will never receive SETTINGS_CHANGE_UNAVAILABLE
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mLocationClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With