Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
This repository was archived by the owner on Jul 8, 2025. It is now read-only.

Read Google Fit automatically generated activities #60

@mdroid23

Description

@mdroid23

I'm struggling getting this to work as expected. I need to enumerate all the activities I see in Google Fit app (e.g auto "morning walk" or manual added running). I've used the following query:

DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.enableServerQueries()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.bucketByTime(1, TimeUnit.DAYS)
.build();
Note: this kind of aggregation is deprecated, but I cannot find the "right" way to receive the same result with the non-deprecated method.

Now: in my example day on Fit, I've two activities. The first is auto-generated "afternoon walk" of 2.32km and 32 min, the second is a manual added running activity of 1h. The query above returns two rows with fields activity/duration/num_segments:

Running / 3600000 (1h) / 1
Walking / 2674044 (~44mins) / 10
As you can see I get 12 minutes added for walking, why? How can I get the exact thing I see in the app? Moreover the total sum of steps for that day is not the sum of the two activities I see on Fit. What a mess...

EDIT: about timezone I'm getting it this way:

Calendar calendar = Calendar.getInstance(Locale.getDefault());
long endTime = calendar.getTimeInMillis();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long startTime = calendar.getTimeInMillis();
And these are the results for the specific day:

DATA TYPE: DataType{com.google.activity.summary[activity(i), duration(i), num_segments(i)]}

AS ACTIVITY: running FIELD: activity(i) START TIME: Fri Oct 16 12:10:00 GMT+02:00 2020 END TIME: Fri Oct 16 13:10:00 GMT+02:00 2020

DURATION: 3600000 FIELD: duration(i) START TIME: Fri Oct 16 12:10:00 GMT+02:00 2020 END TIME: Fri Oct 16 13:10:00 GMT+02:00 2020

N. SEGMENTS: 1 FIELD: num_segments(i) START TIME: Fri Oct 16 12:10:00 GMT+02:00 2020 END TIME: Fri Oct 16 13:10:00 GMT+02:00 2020

AS ACTIVITY: walking FIELD: activity(i) START TIME: Fri Oct 16 09:20:30 GMT+02:00 2020 END TIME: Fri Oct 16 23:15:17 GMT+02:00 2020

DURATION: 2674044 FIELD: duration(i) START TIME: Fri Oct 16 09:20:30 GMT+02:00 2020 END TIME: Fri Oct 16 23:15:17 GMT+02:00 2020

N. SEGMENTS: 10 2FIELD: num_segments(i) START TIME: Fri Oct 16 09:20:30 GMT+02:00 2020 END TIME: Fri Oct 16 23:15:17 GMT+02:00 2020

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions