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 HistoryClient.readDailyTotal, as shown in the following example:

Fitness.getHistoryClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
    .addOnSuccessListener { result ->
        val totalSteps =
            result.dataPoints.firstOrNull()?.getValue(Field.FIELD_STEPS)?.asInt() ?: 0
        // Do something with totalSteps
    .addOnFailureListener { e ->
        Log.i(TAG, "There was a problem getting steps.", e)

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:

val startTime =
val endTime =

val datasource = DataSource.Builder()

val request = DataReadRequest.Builder()
    .bucketByTime(1, TimeUnit.DAYS)
    .setTimeRange(startTime.toEpochSecond(), endTime.toEpochSecond(), TimeUnit.SECONDS)

Fitness.getHistoryClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
    .addOnSuccessListener { response ->
        val totalSteps = response.buckets
            .flatMap { it.dataSets }
            .flatMap { it.dataPoints }
            .sumBy { it.getValue(Field.FIELD_STEPS).asInt() }
        Log.i(TAG, "Total steps: $totalSteps")

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 \