Search in sources :

Example 1 with GeofencingRequest

use of com.google.android.gms.location.GeofencingRequest in project Android-ReactiveLocation by mcharmas.

the class GeofenceActivity method addGeofence.

private void addGeofence() {
    final GeofencingRequest geofencingRequest = createGeofencingRequest();
    if (geofencingRequest == null)
        return;
    final PendingIntent pendingIntent = createNotificationBroadcastPendingIntent();
    reactiveLocationProvider.removeGeofences(pendingIntent).flatMap(new Func1<Status, Observable<Status>>() {

        @Override
        public Observable<Status> call(Status pendingIntentRemoveGeofenceResult) {
            return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest);
        }
    }).subscribe(new Action1<Status>() {

        @Override
        public void call(Status addGeofenceResult) {
            toast("Geofence added, success: " + addGeofenceResult.isSuccess());
        }
    }, new Action1<Throwable>() {

        @Override
        public void call(Throwable throwable) {
            toast("Error adding geofence.");
            Log.d(TAG, "Error adding geofence.", throwable);
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) GeofencingRequest(com.google.android.gms.location.GeofencingRequest) PendingIntent(android.app.PendingIntent) Func1(rx.functions.Func1)

Aggregations

PendingIntent (android.app.PendingIntent)1 Status (com.google.android.gms.common.api.Status)1 GeofencingRequest (com.google.android.gms.location.GeofencingRequest)1 Func1 (rx.functions.Func1)1