我知道GoogleFit常见问题解答中已经提到了此问题,他们对此有解决方案https://developers.google.com/fit/faq#values_for_stepdistanceactive_timecalories_do_not_match_those_of_fit_app
但是,它仍然在某些设备中发生。
这是我的代码,用于检索今天的拟合数据
Log.i(TAG, "Start query: " + format(startTime) + " End query: " + format(endTime))
val ESTIMATED_STEP_DELTAS = DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build()
val readRequest = DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.aggregate(DataType.TYPE_CALORIES_EXPENDED, DataType.AGGREGATE_CALORIES_EXPENDED)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build()
Fitness.getHistoryClient(context, GoogleSignIn.getLastSignedInAccount(context)!!)
.readData(readRequest)
.addOnSuccessListener({ response ->
for (bucket in response.buckets) {
dumpDataSet(bucket)
}
})
.addOnFailureListener({ e -> Log.e(TAG, "onFailure()", e) })
Fitness.getHistoryClient(context, GoogleSignIn.getLastSignedInAccount(context)!!)
.readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
.addOnSuccessListener {
Log.i(TAG, "Data set size: " + it.dataPoints.size)
for (dp in it.dataPoints) {
Log.i(TAG, "Type: " + dp.dataType.name)
Log.i(TAG, "Start: "
+ format(dp.getStartTime(TimeUnit.MILLISECONDS))
+ " End: "
+ format(dp.getEndTime(TimeUnit.MILLISECONDS)))
for (field in dp.dataType.fields) {
Log.i(TAG, "Field:" + field.name + " Value:" + dp.getValue(field))
}
}
}
private fun dumpDataSet(bucket: Bucket) {
val fitData = FitData()
for (dps in bucket.dataSets) {
for (dp in dps.dataPoints) {
Log.i(TAG, "Type: " + dp.dataType.name)
Log.i(TAG, "Start: "
+ format(dp.getStartTime(TimeUnit.MILLISECONDS))
+ " End: "
+ format(dp.getEndTime(TimeUnit.MILLISECONDS)))
for (field in dp.dataType.fields) {
Log.i(TAG, "Field:" + field.name + " Value:" + dp.getValue(field))
}
}
}
}
Sony Z5 logcat打印是
GoogleFitHistory: Start query: 2018-07-25 00:00:00 End query: 2018-07-25 15:56:04
GoogleFitHistory: Type: com.google.step_count.delta
GoogleFitHistory: Start: 2018-07-25 10:39:36 End: 2018-07-25 15:17:45
Field:steps Value:123
Type: com.google.calories.expended
GoogleFitHistory: Start: 2018-07-25 00:00:00 End: 2018-07-25 15:17:35
Field:calories Value:1116.4005
在健身应用中,步长为 161 ,而卡路里为 1146 。
在几乎测试中,我看到“历史记录”的步骤与Fit应用程序相同,但有时有所不同。
不同的值很小,但有时可能会很大
我还使用HistoryClient#readDailyTotal测试了历史记录,但问题仍然存在。
任何帮助或建议将不胜感激