我正在尝试获取日历中设置的一天中消耗的卡路里数。问题是,即使我从未来中选择一天,每天的卡路里数字的值也介于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();
}