android - google fit 中的卡路里值错误
问题描述
我正在尝试获取一天中燃烧的卡路里数量,这是在日历中设置的日期。问题是,即使我从未来选择一天,每天的卡路里数值也在 1400 到 1500 之间。
private void updateInfo() {
final GoogleApiClient client = new GoogleApiClient.Builder(getContext())
.addApi(Fitness.HISTORY_API)
.build();
client.connect();
final PendingResult<DataReadResult> dataReadResultPendingResult = Fitness.HistoryApi.readData(client, new DataReadRequest.Builder()
.setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
.bucketByTime(1, TimeUnit.DAYS)
.aggregate(TYPE_CALORIES_EXPENDED, AGGREGATE_CALORIES_EXPENDED)
.build());
final Handler handler = new Handler();
new Thread() {
@Override
public void run() {
final DataReadResult totalResult = dataReadResultPendingResult.await(30, SECONDS);
if (totalResult.getStatus().isSuccess()) {
handler.post(new Thread() {
@Override
public void run() {
quantityCaloriesSpent.setText(totalResult.getBuckets().get(0).getDataSets().get(0).getDataPoints().get(0).getValue(FIELD_CALORIES).asFloat()+ "");
}
});
} else {
// handle failure
}
}
}.start();
}
解决方案
推荐阅读
- r - R绕过ssl安装包
- stored-procedures - Snowflake 使用来自另一个存储过程的参数调用存储过程
- shell - 如何将脚本外壳的结果与applescript一起使用?
- sdk - Facebook Audience Network SDK 错误(编译时错误)
- vba - 从新列访问 vba 数据表
- google-cloud-functions - Node.js 的冷启动
- angular - 带有 Angular 的 bokehjs:导入时出错
- matlab - MATLAB 积分 2 为 2 个数学上等价的表达式返回不同的值
- webrtc - Azure 上的 Coturn 负载均衡
- web - 为已发布二进制文件的公共存储库寻找解决方案,可使用 wget 工具恢复