2

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; !!
                }
            }
        });
    }
Wooff
  • 1,091
  • 12
  • 23
  • possible duplicate of [How to check if Location Services are enabled?](http://stackoverflow.com/questions/10311834/how-to-check-if-location-services-are-enabled) – Marian Paździoch Jan 28 '15 at 15:05
  • 3
    This is NOT duplicate question ! My question is not about how to check location availability, but how to be notified when that happended. I don't want to periodically calling check method. I want to be called back by system. – Wooff Jan 29 '15 at 08:35
  • indeed I've set wrong duplicate, this is right one: possible duplicate of http://stackoverflow.com/questions/25156977/google-location-services-vs-android-location-services/25160005#25160005 – Marian Paździoch Jan 29 '15 at 08:38

0 Answers0