Google Fit SessionsApi not returning all sessions in time range

不打扰是莪最后的温柔 提交于 2019-12-08 15:35:11

问题


Somehow I've run into a dead end with the Google Fit Android SDK. Currently I'm building an application that reads, displays and processes data from Google Fit to give users insights on their workout behavior.

My situation is as follows: I used to test on a Google Pixel - everything was fine and I've received all (more than 20) sessions from Google Fit. One week ago, I've switched to a HTC10 - on this device I'm only receiving 4 (!) sessions from Google Fit - same app, same code, same Google Fit account (in the Google Fit app I can still see all workouts and sessions). The sessions I'm trying to read were not created with my app, but instead with the Google Fit app itself. But still, on the old phone I could read them, on the new one I can not.

Let me paste some code for additional clarity.

GoogleApiClient Set-Up

googleApiClient = GoogleApiClient.Builder(context)
    .addApi(Fitness.HISTORY_API)
    .addApi(Fitness.SESSIONS_API)
    .addApi(Fitness.RECORDING_API)
    .addApi(Fitness.GOALS_API)
    .addScope(Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
    .addScope(Scope(Scopes.FITNESS_BODY_READ_WRITE))

After connecting, I subscribe to several RecordingApis (TYPE_WORKOUT_EXERCISE, TYPE_WEIGHT, TYPE_CALORIES_EXPENDED)

SessionReadRequest:

   val sessionRequest = SessionReadRequest.Builder()
                .setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
                .read(DataType.TYPE_WORKOUT_EXERCISE)
                .readSessionsFromAllApps()
                .enableServerQueries()
                .build()

Reading the sessions:

       Fitness.SessionsApi.readSession(googleApiClient, sessionRequest)
        .setResultCallback { result ->
            Timber.d("Sessions result: %s", result.status)
                Timber.d("Got %d sessions", result.sessions.size) // returns only 4! for 2014-NOW timerange
       }

Any help would be appreciated.


回答1:


Google fit api only return data from local cache, it will return data between two date that you ask for and available in Google-Fit app.



来源:https://stackoverflow.com/questions/46532384/google-fit-sessionsapi-not-returning-all-sessions-in-time-range

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