@Override
 public void onConnected(Bundle bundle) {
   Log.d("GEO", "Location client connected");
   if (mAction == Action.ADD) {
     GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
     Log.d("GEO", "Location client adds geofence");
     builder.setInitialTrigger(
         transitionType == Geofence.GEOFENCE_TRANSITION_ENTER
             ? GeofencingRequest.INITIAL_TRIGGER_ENTER
             : GeofencingRequest.INITIAL_TRIGGER_EXIT);
     builder.addGeofences(mGeofenceListsToAdd);
     GeofencingRequest build = builder.build();
     LocationServices.GeofencingApi.addGeofences(mGoogleApiClient, build, getPendingIntent())
         .setResultCallback(
             new ResultCallback<Status>() {
               @Override
               public void onResult(@NonNull Status status) {
                 if (status.isSuccess()) {
                   String msg = "Geofences added: " + status.getStatusMessage();
                   Log.e("GEO", msg);
                   Toast.makeText(GeofencingService.this, msg, Toast.LENGTH_SHORT).show();
                 }
                 GeofencingService.this.onResult(status);
               }
             });
   }
 }
  /**
   * Builds and returns a GeofencingRequest. Specifies the list of geofences to be monitored. Also
   * specifies how the geofence notifications are initially triggered.
   */
  private GeofencingRequest getGeofencingRequest() {
    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();

    // The INITIAL_TRIGGER_ENTER flag indicates that geofencing service should trigger a
    // GEOFENCE_TRANSITION_ENTER notification when the geofence is added and if the device
    // is already inside that geofence.
    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);

    // Add the geofences to be monitored by geofencing service.
    builder.addGeofences(mGeofenceList);

    // Return a GeofencingRequest.
    return builder.build();
  }
Esempio n. 3
0
 private GeofencingRequest getGeoFencingRequest(List<Geofence> geofences) {
   GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
   builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
   builder.addGeofences(geofences);
   return builder.build();
 }