gpt4 book ai didi

android - 从 History api 接收的步数数据与 google fit 不匹配

转载 作者:行者123 更新时间:2023-11-29 23:28:26 24 4
gpt4 key购买 nike

我希望在我的应用程序中使用 google fit steps count,因为我使用的是 google 提供的 History api。我发现从 history api 接收的步骤与 google fit 不匹配,即使我使用了 google 提供的相同代码。下面是我的代码。

  Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
long startTime = cal.getTimeInMillis();

DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();

DataReadRequest readRequest = new DataReadRequest.Builder()
.aggregate(ESTIMATED_STEP_DELTAS, DataType.AGGREGATE_STEP_COUNT_DELTA)
.aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

Task<DataReadResponse> result = Fitness.getHistoryClient(getApplicationContext(),
GoogleSignIn.getLastSignedInAccount(getApplicationContext())).readData(readRequest);

任何帮助将不胜感激,我长期以来一直被这个问题困扰,甚至没有从谷歌找到任何合适的教程。

最佳答案

参见 FAQ ,它从字面上解释了您正在描述的行为。

这可能是最接近的;假设设备上安装了最新的 Play 服务:

DataSource ESTIMATED_STEP_DELTAS = new DataSource.Builder()
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.setAppPackageName("com.google.android.gms")
.build();

DataReadRequest readRequest = new 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)
.aggregate(DataType.TYPE_ACTIVITY_SEGMENT, DataType.AGGREGATE_ACTIVITY_SUMMARY)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.build();

除了 TYPE_CALORIES_EXPENDED 外,它完全一样。或者,您可以记录自己的 sessions - 这不仅是 estimated_steps,而且具有唯一的 session 标识符。

关于android - 从 History api 接收的步数数据与 google fit 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53128859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com