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.
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.
Usually when the distance shows up incorrectly it's because Google Fit wasn't able to maintain a GPS fix throughout the entire activity.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With