Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeofencingApi is deprecated #23

Open
Moh09 opened this issue Dec 30, 2018 · 1 comment
Open

GeofencingApi is deprecated #23

Moh09 opened this issue Dec 30, 2018 · 1 comment

Comments

@Moh09
Copy link

Moh09 commented Dec 30, 2018

It have been replace by "GeofencingClient" but how do you integrate that in the code ?

    public void registerAllGeofences(){
        if (mGoogleApiClient == null || mGoogleApiClient.isConnected() || mGeofenceList == null || mGeofenceList.size() == 0) {
            return;
        }
        try {
            LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, getGeofencingRequest(), getGeofencePendingIntent()).setResultCallback(this);
        } catch (SecurityException securityException) {
            Log.e(TAG, securityException.getMessage());
        }
    }

    public void unRegisterAllGeofences() {
        if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
            return;
        }
        try {
            LocationServices.GeofencingApi.removeGeofences(
                    mGoogleApiClient,
                    // This is the same pending intent that was used in registerGeofences
                    getGeofencePendingIntent()
            ).setResultCallback(this);
        } catch (SecurityException securityException) {
            // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
            Log.e(TAG, securityException.getMessage());
        }
    }

Become ?

@brccabral
Copy link

-public class Geofencing implements ResultCallback {
+public class Geofencing implements OnSuccessListener, OnFailureListener {

+ private GeofencingClient geofencingClient;

//onCreate()
+ geofencingClient = LocationServices.getGeofencingClient(mContext);

//registerAllGeofences()
- LocationServices.GeofencingApi.addGeofences(
- mGoogleApiClient,
- getGeofencingRequest(),
- getGeofencePendingIntent()
- ).setResultCallback(this);
+ geofencingClient.addGeofences(getGeofencingRequest(), getGeofencePendingIntent())
+ .addOnSuccessListener(this)
+ .addOnFailureListener(this);

//unRegisterAllGeofences()
- LocationServices.GeofencingApi.removeGeofences(
- mGoogleApiClient,
+ geofencingClient.removeGeofences(

- ).setResultCallback(this);
+ ).addOnSuccessListener(this)
+ .addOnFailureListener(this)
+ ;

- public void updateGeofencesList(PlaceBuffer places) {
+ public void updateGeofencesList(List<Place> places) {

- if (places == null || places.getCount() == 0) return;
+ if (places == null || places.size() == 0) return;

- public void onResult(@NonNull Result result) {
- Log.e(TAG, String.format("Error adding/removing geofence : %s",
- result.getStatus().toString()));
+ public void onFailure(@NonNull Exception e) {
+ Log.d(TAG, "onFailure: Geofence add failure");

+ @Override
+ public void onSuccess(Object o) {
+ Log.d(TAG, "onSuccess: Geofence adeed");
+ }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants