Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Fit SessionsApi not returning all sessions in time range

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.

like image 900
damian Avatar asked Oct 02 '17 19:10

damian


People also ask

Why is my Google Fit not recording?

Ensure that data syncing for Google Fit is enabled. You can do this on your phone by navigating to: Settings > Accounts > Select your Google account being used for Google Fit > Account sync > Google Fit data. From here, you can confirm that data syncing is enabled for Google Fit or enable it if it is disabled.

Why does Google Fit show incorrect distance?

Usually when the distance shows up incorrectly it's because Google Fit wasn't able to maintain a GPS fix throughout the entire activity.


1 Answers

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.

like image 71
Manu Avatar answered Oct 18 '22 12:10

Manu