5

I'm attempting to fetch the past two weeks of daily step totals with a single request to Google's fitness history API. But the data does not bucket the data by days according to the user's own time zone. At least -- this is my assumption. Here is the output I get compared to the step totals reported in the google fit app:

Field (steps) Key (2015-08-05) Value(5028) | FitApp(4448)
Field (steps) Key (2015-08-06) Value(5158) | FitApp(2973)
Field (steps) Key (2015-08-07) Value(5828) | FitApp(7862)
Field (steps) Key (2015-08-08) Value(5300) | FitApp(4413)
Field (steps) Key (2015-08-10) Value(1071) | FitApp(2741)
Field (steps) Key (2015-08-10) Value(2715) | (duplicate day returned)

Here is the way I form the request:

// Setting a start and end date using a range of 2 weeks before this moment.
Calendar cal = Calendar.getInstance();
Date now = new Date();
cal.setTime(now);
long endTime = cal.getTimeInMillis();
cal.add(Calendar.WEEK_OF_YEAR, -2);
long startTime = cal.getTimeInMillis();

SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
Log.i(TAG, "Range Start: " + dateFormat.format(startTime));
Log.i(TAG, "Range End: " + dateFormat.format(endTime));

DataReadRequest readRequest = new DataReadRequest.Builder()
        .aggregate(DataType.TYPE_STEP_COUNT_DELTA, DataType.AGGREGATE_STEP_COUNT_DELTA)
        .bucketByTime(1, TimeUnit.DAYS)
        .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
        .build();

return Fitness.HistoryApi.readData(mClient, readRequest).await(1, TimeUnit.MINUTES);

Is it possible to have the bucketByTime take the user's time zone into effect so that the step data correlates to what the user sees in the fit app? If not, will I simply need to make an individual request for each day (thus 14 requests as opposed to 1?)

Thanks for your help!

Jim Jeffers
  • 17,572
  • 4
  • 41
  • 49

0 Answers0