Google Fit步骤与历史记录API响应不符
Google Fit 步骤集成出现问题。客户抱怨从 Google Fit 导入的数字与 Google Fit 在自己的 Fit 应用程序中显示的数字不一样。
根据 Google Fit 文档“获取与健身应用程序相同的每日步数”,我们执行以下操作:
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)
}
}
但它似乎并不适用于所有情况。
例如,4 月 4 日显示 6649 步。 如果我进入“查看源数据”,将会有 88 条记录。 如果我总结所有这些,我会得到 7362,但我想这没关系,因为 Google Fit 通过应用一些智能逻辑删除了一些重叠的条目。
所以我试图将这 6649 个步骤添加到我的应用程序中,但上面的代码返回
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 (不是 6649)
对于许多其他日期,此代码工作得很好:我得到的数字与 Google Fit 应用程序中的数字相同。所以我认为这是 Google Fit 方面的某种错误,或者我不知道一些神奇的知识。
任何帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论