I am able to succesfully register geofence, but only when GPS is enabled. When GPS is disabled I got error GEOFENCE_NOT_AVAILABLE (1000). Since it is not critical to register it "just now". I don't want to bother user with (enable GPS first) popup.
Is there a way how to register callback to be notified when user finally enable GPS? Or any other way how to execute code when location is available to repeat geofence registration.
NOTE: I need solution for GoogleApiClient (Google Play Services >6.5), but same problem exist on LocationClient (<6.5).
Thanks.
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
...
@Override
public void onConnected(Bundle bundle) {
PendingResult<Status> result = LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, geofencesToAdd, mGeofencePendingIntent);
result.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if (status.isSuccess()) {
// Successfully registered
} else if (status.hasResolution()) {
// Google has resolution
} else {
// Error
// status.getStatusCode() == LocationStatusCodes.GEOFENCE_NOT_AVAILABLE; !!
}
}
});
}