Read the Daily Step Total

This section demonstrates reading current daily step count data using the Fit Android API and Fit REST API.


Your app can read the current daily step total by calling HistoryApi.readDailyTotal, as shown in the following example:

private class VerifyDataTask extends AsyncTask<Void, Void, Void> {
    protected Void doInBackground(Void... params) {

        long total = 0;

        PendingResult<DailyTotalResult> result = Fitness.HistoryApi.readDailyTotal(mClient, DataType.TYPE_STEP_COUNT_DELTA);
        DailyTotalResult totalResult = result.await(30, TimeUnit.SECONDS);
        if (totalResult.getStatus().isSuccess()) {
            DataSet totalSet = totalResult.getTotal();
            total = totalSet.isEmpty()
                    ? 0
                    : totalSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS).asInt();
        } else {
            Log.w(TAG, "There was a problem getting the step count.");

        Log.i(TAG, "Total steps: " + total);

        return null;

The daily total is computed from midnight of the current day on the device's current timezone.

To get the same daily step count as the Fit app, create a data source using the package, as shown in the following example:

final DataSource ds = new DataSource.Builder()

final DataReadRequest req = new DataReadRequest.Builder()
.aggregate(ds, DataType.AGGREGATE_STEP_COUNT_DELTA)
    .bucketByTime(1, TimeUnit.DAYS)
  .setTimeRange(timeBounds[0], timeBounds[1], TimeUnit.MILLISECONDS)

For more information about working with aggregate data sources, see Work with the Fitness History.


Your app can read the current daily step count total across all data sources by making a POST request and querying the data type for the specified time period.

HTTP method


Request URL

Request body

  "aggregateBy": [{
    "dataTypeName": "",
    "dataSourceId": ""
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1438705622000,
  "endTimeMillis": 1439310422000

Curl command

curl \
-H "Content-Type: application/json;encoding=utf-8" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d @aggregate.json \

Send feedback about...