0

i try to collecting data from 1 april 2023 to 30 april 2023, today is 20 april 2023 but health connect still provides data for > 20 april 2023 like this data from health connect

i don't know where the data is coming from, i just sync google fit data to health connect, when i check health connect, there is no data from > 20 april 2023, same case if for example i have no data in february but health connect still give a data, i guess that is default value? this is my code

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

this only happens with data type TotalCalorieBurned and using aggregate, another example is when i set the date into december 2022 (no data here) and i check the data in health connect app with the same date, there is no data

no data in health connect

but when i red in my app, health connect given data

health connect given data that must be no data

my health connect version androidx.health.connect:connect-client:1.0.0-alpha11

  • Possibly some default values (all *future* values are exactly the same). Can you dynamically collect data until *today* (the current day)? Or simply ignore future dates? Maybe adjust the `parameters.endDate` if it is in the future. – deHaar Apr 20 '23 at 07:23
  • of course i can, but i have another problem that if you don't have data in some date, health connect still give a data, for example, i have no data in 4-10 february but health connect keep give me a data like in the image – Rizki Rakasiwi Apr 20 '23 at 09:06
  • 1
    Did you checked how many apps are connected with health connect and sending data over ? Might be seems for those days Google fit doesnt have data but any other app can have those data which are synced with health connect. – Rajesh Koshti May 01 '23 at 14:49

1 Answers1

0

i found the problem, when i checked "dataOrigins" i found unknown data origin with package name __platform print data origin

i solve this by filtered the data like this

for (dataOrigins in weeklyResult.result.dataOrigins){
  if (dataOrigins.packageName == DataOrigins.GoogleFit.packageName)
   // code here
}
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 01 '23 at 18:23