You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Health Connect聚合查询返回无数据时段异常数据问题求助

问题:Health Connect聚合查询TotalCaloriesBurned数据异常
  • 查询2023年4月1日至4月30日的卡路里数据(当前日期为2023年4月20日)时,Health Connect返回了4月20日之后的数据,但Health Connect应用内查询无该时段数据,且仅同步了Google Fit数据到Health Connect。
  • 查询2022年12月数据时,Health Connect应用显示无数据,但应用通过代码查询却返回了数据。

该问题仅在使用aggregate查询TotalCaloriesBurned数据类型时出现,使用的Health Connect版本为androidx.health.connect:connect-client:1.0.0-alpha11,相关代码如下:

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()
    )
}

内容的提问来源于stack exchange,提问作者Rizki Rakasiwi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 13:03:19