The interval of results from Google's activity recognition isn't regular

若如初见. 提交于 2020-01-14 14:06:03

问题


I was working on google's activity recognition and finally I got results from this service.

However, The function requestActivityUpdates(long detectionIntervalMillis, PendingIntent callbackIntent) doesn't seem to work correctly. The detection interval is not regular and decreases to 30~50 seconds when my current activity is changing. It doesn't work like the live demo on google I/O 2013 (Google I/O 2013 Location API, from 27:47 to 28:45). Does anyone have same issue on it?


回答1:


Well it's a bit confusing but the variable long detectionIntervalMillis does not fix the interval - it sets the maximum interval between two updates.

As it's said in the official documentation:

Activities may be received more frequently than the detectionIntervalMillis parameter if another application has also requested activity updates at a faster rate. It may also receive updates faster when the activity detection service receives a signal that the current activity may change, such as if the device has been still for a long period of time and is then unplugged from a phone charger.

Documentation




回答2:


Instead of adding the build() part on onCreate directly try adding the method below and call it on onCreate(). And try to trace the code from google sample I got the code stripped down from that sample.

protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(ActivityRecognition.API)
            .build();
}

and add buildGoogleApiClient() to your onCreate method ;) this works great for me!



来源:https://stackoverflow.com/questions/19303382/the-interval-of-results-from-googles-activity-recognition-isnt-regular

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