我正在研究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))));
}
}