使用Google Fit API燃烧积极的卡路里



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

您可以在此处检查此链接,您可以在特定日期中获得如何过滤出活跃的卡路里(在跑步和步行时消耗的卡路里(。

最新更新