So I\'m trying to create an app that connects to Google Fit and shows the user their data in a pretty streamlined way and I\'m having trouble finding the calories the user b
You need to work with Fitness.SESSIONS_API, instead of Fitness.HISTORY_API. Sessions represent a time interval during which users perform a fitness activity.
You can get calories for various activities for each day by using the following code
DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
.bucketByActivityType(1, TimeUnit.SECONDS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();
You can run this code in a loop to get data for as many days as you want. It will return data buckets for all activities and you can fetch activity name from the bucket by this method that returns activity name as String
bucket.getActivity();
Store it in a custom Collection and you are good to go. Hope it helps! :)