Reputation: 21
I am working on the fitness app for android. I am fetching the calories burned from the Google fit API but it's giving me the inactive + active calories. I want only the active calories burned. Can anyone please help me out in this.
Here is the code I am using for fetching the calories burned from 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))));
}
}
Upvotes: 2
Views: 1745
Reputation: 2301
You can check this link here you can get how to filter out active calories (calories consumed while Running and Walking) for a particular date.
Upvotes: 0