Google Fit API, getting calories burned per activity

前端 未结 2 696
悲&欢浪女
悲&欢浪女 2021-01-05 06:27

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

相关标签:
2条回答
  • 2021-01-05 07:05

    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.

    0 讨论(0)
  • 2021-01-05 07:16

    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! :)

    0 讨论(0)
提交回复
热议问题