Got a problem with Google Fit steps integration. The customers complain that the numbers imported from the Google Fit are not the same as the ones Google Fit shows in its own Fit app.
As per Google Fit documentation “to get the same daily step count as the Fit app” we do the following:
val startDateTime = DateTime.now().withTimeAtStartOfDay().minusDays(14).millis
val endDateTime = DateTime.now().millis
val datasource = DataSource.Builder()
.setAppPackageName("com.google.android.gms")
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.build()
val readRequest = DataReadRequest.Builder()
.aggregate(datasource)
.bucketByTime(1, TimeUnit.MINUTES)
.setTimeRange(startDateTime, endDateTime, TimeUnit.MILLISECONDS)
.build()
GoogleSignIn.getLastSignedInAccount(context)?.let {
Fitness.getHistoryClient(context, it)
.readData(readRequest)
.addOnSuccessListener { dataReadResponse ->
repository.readAndSaveBuckets(dataReadResponse)
}
}
However it doesn’t seem to work in every case.
For example, for Apr 4th it shows 6649 steps. If I go to “See source data” there will be 88 records. If I summarise all of them, I’ll get 7362 but I guess that’s okay, since Google Fit removes some of the overlapping entries by applying some smart logic.
So I’m trying to get those 6649 steps to my app but the code above returns
StartDateTime EndDateTime Steps
2022-04-04T08:59:56.072+0200 2022-04-04T09:00:00.000+0200 2
2022-04-04T09:00:00.000+0200 2022-04-04T09:15:33.084+0200 1661
2022-04-04T09:45:53.807+0200 2022-04-04T09:54:41.917+0200 806
2022-04-04T16:50:06.160+0200 2022-04-04T16:51:06.160+0200 10
2022-04-04T17:03:21.121+0200 2022-04-04T17:16:18.422+0200 23
2022-04-04T17:46:09.064+0200 2022-04-04T17:47:09.064+0200 11
2022-04-04T18:33:57.089+0200 2022-04-04T18:42:31.094+0200 682
2022-04-04T19:11:41.109+0200 2022-04-04T19:30:00.000+0200 926
2022-04-04T19:30:00.000+0200 2022-04-04T19:43:56.096+0200 1648
2+1661+806+10+23+11+682+926+1648 = 5769 (not 6649)
For many other dates this code works just fine: I get the same numbers as in the Google Fit app. So I assume it’s some sort of a bug on Google Fit side or I don’t know some magic piece of knowledge.
Any help would be appreciated!