1

I'm trying to get the number of calories burn in a day, day which is set in a calendar. The problem is that the numbers for calories for each day have value between 1400 and 1500, even if i select a day from the future.

private void updateInfo() {

final GoogleApiClient client = new GoogleApiClient.Builder(getContext())
        .addApi(Fitness.HISTORY_API)
        .build();

client.connect();


final PendingResult<DataReadResult> dataReadResultPendingResult = Fitness.HistoryApi.readData(client, new DataReadRequest.Builder()
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .bucketByTime(1, TimeUnit.DAYS)
        .aggregate(TYPE_CALORIES_EXPENDED, AGGREGATE_CALORIES_EXPENDED)
        .build());


final Handler handler = new Handler();
new Thread() {
    @Override
    public void run() {
        final DataReadResult totalResult = dataReadResultPendingResult.await(30, SECONDS);
        if (totalResult.getStatus().isSuccess()) {

            handler.post(new Thread() {
                @Override
                public void run() {
                    quantityCaloriesSpent.setText(totalResult.getBuckets().get(0).getDataSets().get(0).getDataPoints().get(0).getValue(FIELD_CALORIES).asFloat()+ "");
                }
            });

        } else {
            // handle failure
        }
    }
}.start();

}
thmmy95
  • 361
  • 2
  • 18

0 Answers0