Android ActivityRecognitionApi requestActivityUpdates are too frequent. How can I throttle them?

好久不见. 提交于 2019-12-13 04:50:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!