mcharmas / Android-ReactiveLocation

Small library that wraps Google Play Service API in brilliant RxJava Observables reducing boilerplate to minimum.
2.11k stars 313 forks source link

getDetectedActivity is only getting called once. #186

Open aalap03 opened 6 years ago

aalap03 commented 6 years ago

This is my code to post location to server with two filters 1) if my device is not still and 2) if it has accuracy less than 40

With delay parameter in detectedActivity Observable as 0 and my LocationRequest Interval is also 5 secs.I expect logs in zip method frequently (and not in the onNext or onError as my device is still) but I only see log with test zip once. If I have understood it wrong please correct me or please let me know where I have made mistake in my code below.

   long INTERVAL = 1000*5;
   locationRequest = LocationRequest
            .create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(INTERVAL)
            .setFastestInterval(INTERVAL);

   Observable<Location> updatedLocation = provider.getUpdatedLocation(locationRequest);
   Observable<ActivityRecognitionResult> detectedActivity = provider.getDetectedActivity(0);

    compositeDisposable.add(
            Observable.zip(updatedLocation, detectedActivity, (location, result) -> {
                isDeviceMoving = result.getMostProbableActivity().getType() != DetectedActivity.STILL;
                Log.d(TAG, "test: zip moving ? " + isDeviceMoving);
                return location;
            })
                    .filter(location -> isDeviceMoving)
                    .filter(location -> location.getAccuracy() <= 40)
                    .subscribe(location -> Log.d(TAG, "test: " + location)
                            , throwable -> Log.d(TAG, "test: er " + throwable.getLocalizedMessage())));