【发布时间】:2018-08-09 01:54:40
【问题描述】:
我正在开发适用于 Android 的健身应用程序。我正在从 Google fit API 中获取燃烧的卡路里,但它给了我不活跃的 + 活跃的卡路里。我只想要燃烧的活跃卡路里。谁能帮我解决这个问题。
这是我用于从 Google fit API 获取消耗的卡路里的代码:
private class FetchCalorieAsync extends AsyncTask<Object, Object, Float> {
protected Float doInBackground(Object... params) {
float total = 0;
PendingResult<DailyTotalResult> result = Fitness.HistoryApi.readDailyTotal(googleApiClient, DataType.AGGREGATE_CALORIES_EXPENDED);
DailyTotalResult totalResult = result.await(30, TimeUnit.SECONDS);
if (totalResult.getStatus().isSuccess()) {
DataSet totalSet = totalResult.getTotal();
if (totalSet != null) {
total = totalSet.isEmpty() ? 0 : totalSet.getDataPoints().get(0).getValue(Field.FIELD_CALORIES).asFloat();
}
} else {
Log.w(TAG, "There was a problem getting the calories.");
}
return total;
}
@Override
protected void onPostExecute(Float aLong) {
super.onPostExecute(aLong);
tvCalorieBurnt.setText(String.valueOf((int)(Math.round(aLong))));
}
}
【问题讨论】:
标签: android google-fit