问题
I'm trying to change how often I request location updates from the FusedLocationProviderAPI based on the activity level of the user. Android provides an ActivityRecognitionApi which would be great, but unfortunately:
"Activities may be received more frequently than the detectionIntervalMillis parameter if another application has also requested activity updates at a faster rate." (From: https://developer.android.com/reference/com/google/android/gms/location/ActivityRecognitionApi.html)
I'd like to execute code no more often than once every, say, 10 seconds. What's the best way to do this?
回答1:
You have probably found a solution by now, but..
I am currently working on a fork of https://github.com/mcharmas/Android-ReactiveLocation trying to add Activity Recognition. Using an RxJava observer, you easily define a filter that only let new activities go to the subscribe() method if x seconds has passed.
The fork can be found here: https://github.com/cyrixmorten/Android-ReactiveLocation
来源:https://stackoverflow.com/questions/27500602/android-activityrecognitionapi-requestactivityupdates-are-too-frequent-how-can