我尝试收集 2023 年 4 月 1 日至 2023 年 4 月 30 日的数据,今天是 2023 年 4 月 20 日,但 health connect 仍然像这样提供 > 2023 年 4 月 20 日的数据
我不知道数据来自哪里,我只是将 google fit 数据同步到 health connect,当我检查 health connect 时,没有 2023 年 4 月 20 日以上的数据,这是我的代码
override suspend fun getMonthlyHistoriesCalorie(parameter: GetMonthlyHistoriesCalorieParameter): GetMonthlyHistoriesCalorieResponse {
val result = mutableListOf<Double>()
if (isHealthConnectSDKAvailable(context)) {
val healthConnectClient = HealthConnectClient.getOrCreate(context)
val response = healthConnectClient.aggregateGroupByPeriod(
AggregateGroupByPeriodRequest(
metrics = setOf(TotalCaloriesBurnedRecord.ENERGY_TOTAL),
timeRangeFilter = TimeRangeFilter.between(
startTime = LocalDateTime.ofInstant(parameter.startDate, ZoneId.systemDefault()),
endTime = LocalDateTime.ofInstant(parameter.endDate, ZoneId.systemDefault())
),
timeRangeSlicer = Period.ofDays(1)
)
)
for (monthlyResult in response) {
val totalCalorieBurned =
monthlyResult.result[TotalCaloriesBurnedRecord.ENERGY_TOTAL]?.inKilocalories
if (totalCalorieBurned != null) {
result.add(totalCalorieBurned)
}
}
}
return GetMonthlyHistoriesCalorieResponse(
histories = result,
period = DateTimeFormatter.ofPattern("MMMM yyyy").withZone(ZoneId.systemDefault())
.format(parameter.endDate),
total = result.sum()
)
}
我的健康连接版
androidx.health.connect:connect-client:1.0.0-alpha11