I want to implement a dialog box in which they ask users to decide whether you want to enable wifi and gps in the location, but onActivityResult always returns 0, even if the ok button is pressed, in more detail: when wifi and gps are turned off, return 0, but both of them are correct activated (ok button pressed). when gps it is on and off, return 0, but wifi it is activated correctly (ok button is pressed). only when Wi-Fi is on and gps is turned off, it returns -1, but gps is activated correctly (ok button is pressed).
here is my code:
public void activategps(){
builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
final LocationSettingsStates state = result.getLocationSettingsStates();
switch (status.getStatusCode()) {
case LocationSettingsStatusCodes.SUCCESS:
Log.i("sms", "estan disponibles");
Toast.makeText(MainActivity.this, "HOLA 1", Toast.LENGTH_SHORT).show();
break;
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
Log.i("sms", "Motrando popup");
Toast.makeText(MainActivity.this, "HOLA 2", Toast.LENGTH_SHORT).show();
try {
status.startResolutionForResult(
MainActivity.this,
REQUEST_CHECK_SETTINGS);
} catch (SendIntentException e) {
}
break;
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Toast.makeText(MainActivity.this, "HOLA 3", Toast.LENGTH_SHORT).show();
break;
}
}
});
}
and here is the onActivityResult method:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CHECK_SETTINGS:
switch (resultCode) {
case Activity.RESULT_OK:
Log.i("sms", "Se se activaron correctamente");
break;
case Activity.RESULT_CANCELED:
Log.i("sms", "No se activaron ");
break;
default:
break;
}
break;
}
}
I hope you help me, I really need it.