I would like to check if the user has GPS turned on, and if the user does not have gps turned on I would like to offer the user to turn it on.
I am following the guide on developer.android and since they are using updated API I find it hard to find good examples online.
this is my code
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
//...
SettingsClient client = LocationServices.getSettingsClient(this);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
// All location settings are satisfied. The client can initialize
// location requests here.
// ...
createLocationRequest();
}
});
task.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (e instanceof ResolvableApiException) {
try {
// Show the dialog by calling startResolutionForResult(),
// and check the result in onActivityResult().
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(MainActivity.this,
REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx){
// Ignore the error.
}
}
}
});
It runs fine, but I dont get a dialog at all. Nothing is happening in my app, nor in logcat...