使用Google健身API

时间:2017-06-23 11:06:28

标签: android google-fit

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

1 个答案:

答案 0 :(得分:0)

您可以在此处查看此link,了解如何过滤特定日期的活跃卡路里(跑步和散步时消耗的卡路里)。