I am trying to query nutrition history data from Google Fit on Android.
The data is inserted via the food-logging app (Lose It).
But when I query the data from the Google Fit History client it retrieves the data only for the first item I inserted in the app. i.e. If I log breakfast with juice and bagel, the macros that will be retrieved from the client are only for the bagel.
My code:
val nowInMillis = 1625656053000;
val weekAgoInMillis = 1625137653000;
val fitnessOptions = FitnessOptions.builder()
.addDataType(DataType.TYPE_NUTRITION)
.addDataType(DataType.AGGREGATE_NUTRITION_SUMMARY)
.build()
val account = GoogleSignIn.getAccountForExtension(activity, fitnessOptions)
coroutineScope.launch {
Fitness.getHistoryClient(activity, account)
.readDailyTotal(DataType.TYPE_NUTRITION)
.addOnSuccessListener { response ->
for (dp in response.dataPoints) {
Log.i(TAG, "Data point:")
Log.i(TAG, "\tType: ${dp.dataType.name}")
Log.i(
TAG, "\tStart: ${
Calendar.getInstance().apply {
timeInMillis = dp.getStartTime(TimeUnit.MILLISECONDS)
}.time
}")
Log.i(
TAG,
"\tEnd: ${
Calendar.getInstance().apply {
timeInMillis = dp.getEndTime(TimeUnit.MILLISECONDS)
}.time
}")
for (field in dp.dataType.fields) {
Log.i(TAG, "\tField: ${field.name.toString()} Value: ${dp.getValue(field)}")
}
}
}
.addOnFailureListener { e -> Log.d(TAG, "OnFailure()", e) }
}
The printed result:
2021-07-06 22:55:17.988 30237-30237/com.metaflow.flutterhealthfitexample I/FlutterHealthFitPlugin: Type: com.google.nutrition.summary
2021-07-06 22:55:17.992 30237-30237/com.metaflow.flutterhealthfitexample I/FlutterHealthFitPlugin: Start: Tue Jul 06 01:00:01 GMT+03:00 2021
2021-07-06 22:55:17.996 30237-30237/com.metaflow.flutterhealthfitexample I/FlutterHealthFitPlugin: End: Tue Jul 06 01:00:01 GMT+03:00 2021
2021-07-06 22:55:18.002 30237-30237/com.metaflow.flutterhealthfitexample I/FlutterHealthFitPlugin: Field: nutrients Value: {calories=111.6, carbs.total=25.792, cholesterol=0.0, dietary_fiber=0.496, fat.saturated=0.0496, fat.total=0.496, protein=1.736, sodium=2.48, sugar=20.832}
2021-07-06 22:55:18.002 30237-30237/com.metaflow.flutterhealthfitexample I/FlutterHealthFitPlugin: Field: meal_type Value: 1
And if I look into the food logging app, I can see the next result, which clearly shows that nutrition info retrieved matches only juice:
I thought that maybe there is an issue with my code, so I downloaded a FitBit app, that able to show nutrition info from Google Fit as well, and it shows the same result:
Any option to get nutrition info for a complete day?

