/** * Removes geofences, which stops further notifications when the device enters or exits * previously registered geofences. */ public void removeGeofences() { if (!mGoogleApiClient.isConnected()) { Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show(); return; } try { // Remove geofences. LocationServices.GeofencingApi.removeGeofences( mGoogleApiClient, // This is the same pending intent that was used in addGeofences(). getGeofencePendingIntent() ).setResultCallback(this); // Result processed in onResult(). geofencesAddedButtonState(false); } catch (SecurityException securityException) { // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. logSecurityException(securityException); geofencesAddedButtonState(true); } }
public void addGeofences() { if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "GOOGLE API CLIENT NOT CONNECTED!!!! "); isWaitingToAdd=true; return; } try { Log.i(TAG, "GEOFENCE ADDED!"); LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, // The GeofenceRequest object. getGeofencingRequest(), // A pending intent that that is reused when calling removeGeofences(). This // pending intent is used to generate an intent when a matched geofence // transition is observed. getGeofencePendingIntent() ).setResultCallback(this); // Result processed in onResult(). } catch (SecurityException securityException) { // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. logSecurityException(securityException); } }
/** * Removes geofences, which stops further notifications when the device enters or exits * previously registered geofences. */ public void removeGeofences() { if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "GOOGLE API CLIENT NOT CONNECTED!!!! "); isWaitingToRemove=true; return; } try { Log.i(TAG, "GEOFENCE REMOVED!"); // Remove geofences. LocationServices.GeofencingApi.removeGeofences( mGoogleApiClient, // This is the same pending intent that was used in addGeofences(). getGeofencePendingIntent() ).setResultCallback(this); // Result processed in onResult(). } catch (SecurityException securityException) { // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. logSecurityException(securityException); } }
@Override public void onConnected(Bundle bundle) { // Now we can do the actual logic List<Geofence> fences = new ArrayList<Geofence>(); fences.add(fence.toGeofence(venue)); geofencingapi = LocationServices.GeofencingApi; if(locationClient != null && locationClient.isConnected() && fences.size() > 0){ GeofencingRequest request = new GeofencingRequest.Builder() .addGeofences(fences) .build(); PendingResult<Status> status = geofencingapi.addGeofences(locationClient, request, geofenceUtils.getTransitionPendingIntent(this)); status.setResultCallback(this, 10, TimeUnit.SECONDS); // disconnect will be done in resultlistener }else if(locationClient != null && locationClient.isConnected()){ locationClient.disconnect(); } }
/** * Adds geofences, which sets alerts to be notified when the device enters or exits one of the * specified geofences. Handles the success or failure results returned by addGeofences(). */ public void addGeofences() { if (!mGoogleApiClient.isConnected()) { Toast.makeText(this, getString(R.string.not_connected), Toast.LENGTH_SHORT).show(); return; } try { LocationServices.GeofencingApi.addGeofences( mGoogleApiClient, // The GeofenceRequest object. getGeofencingRequest(), // A pending intent that that is reused when calling removeGeofences(). This // pending intent is used to generate an intent when a matched geofence // transition is observed. getGeofencePendingIntent() ).setResultCallback(this); // Result processed in onResult(). geofencesAddedButtonState(true); } catch (SecurityException securityException) { // Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission. logSecurityException(securityException); geofencesAddedButtonState(false); } }
@Override public void onConnected(Bundle bundle) { LOGD(TAG, "connected"); geofencingapi = LocationServices.GeofencingApi; }