How to aggregate by exercise type in the Android Health Connect API

146 views Asked by At

I am trying to do an aggregated query on the new Health Connect API to understand how much time a user has spent on different types of exercises (those inserted through the ExerciseSessionRecord). The Google Fit Android API had a way for doing this through bucketByActivityType. Health Connect, from what I understand, doesn't have such a way to aggregate. You can specify EXERCISE_DURATION_TOTAL as an aggregation metric, but that gives you only the total time spent on any exercise, without telling you which.

Does anybody know how to reproduce something like "bucketByActivityType" without having to query all exercises and do the aggregation manually?

1

There are 1 answers

1
Anthony Bartolotte On

I understand that you are trying to reproduce the "bucketByActivityType" functionality from Google Fit Android API in Health Connect API. Unfortunately, as you mentioned, Health Connect API doesn't have a similar way to aggregate by activity type.

One way to achieve this would be to query all the ExerciseSessionRecord data and then group them by activity type manually. You can then calculate the total time spent on each activity type by summing up the duration of all the sessions for that activity type.

Alternatively, you can try using the "filter" parameter in the Health Connect API to filter the ExerciseSessionRecord data by activity type before aggregating the data. This can help reduce the amount of data you need to query and make the aggregation process more efficient.