Read the Daily Step Total
Stay organized with collections
Save and categorize content based on your preferences.
This section demonstrates reading current daily step count data using the Fit
Android API and Fit REST API.
Android
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))
.readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)
.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 com.google.android.gms
app package, as shown in the following example:
val startTime = LocalDate.now().atStartOfDay(ZoneId.systemDefault())
val endTime = LocalDateTime.now().atZone(ZoneId.systemDefault())
val datasource = DataSource.Builder()
.setAppPackageName("com.google.android.gms")
.setDataType(DataType.TYPE_STEP_COUNT_DELTA)
.setType(DataSource.TYPE_DERIVED)
.setStreamName("estimated_steps")
.build()
val request = DataReadRequest.Builder()
.aggregate(datasource)
.bucketByTime(1, TimeUnit.DAYS)
.setTimeRange(startTime.toEpochSecond(), endTime.toEpochSecond(), TimeUnit.SECONDS)
.build()
Fitness.getHistoryClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))
.readData(request)
.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.
REST
Your app can read the current daily step count total across all data
sources by making a POST
request and querying the
com.google.step_count.delta
data type for the specified time period.
HTTP method
POST
Request URL
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
Request body
{
"aggregateBy": [{
"dataTypeName": "com.google.step_count.delta",
"dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1438705622000,
"endTimeMillis": 1439310422000
}
Curl command
curl \
-X POST \
-H "Content-Type: application/json;encoding=utf-8" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d @aggregate.json \
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-28 UTC.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis documentation demonstrates how to access current daily step count data using the Google Fit Android API and the Fit REST API.\u003c/p\u003e\n"],["\u003cp\u003eFor Android, you can retrieve the step count by using \u003ccode\u003eHistoryClient.readDailyTotal\u003c/code\u003e for a simple daily total or by creating a data source for a more detailed, Fit app-like count.\u003c/p\u003e\n"],["\u003cp\u003eTo match the step count displayed in the Google Fit app, ensure you specify the 'com.google.android.gms' app package when building your data source.\u003c/p\u003e\n"],["\u003cp\u003eThe REST API allows access to the daily step count across all data sources by sending a POST request to a specific endpoint with details about the data type and time period.\u003c/p\u003e\n"]]],[],null,["# Read the Daily Step Total\n\nThis section demonstrates reading current daily step count data using the Fit\nAndroid API and Fit REST API. \n\n### Android\n\nYour app can read the current daily step total by calling\n[`HistoryClient.readDailyTotal`](/fit/scenarios/android/reference/com/google/android/gms/fitness/HistoryClient#public-taskdataset-readdailytotal-datatype-datatype),\nas shown in the following example: \n\n```kotlin\nFitness.getHistoryClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))\n .readDailyTotal(DataType.TYPE_STEP_COUNT_DELTA)\n .addOnSuccessListener { result -\u003e\n val totalSteps =\n result.dataPoints.firstOrNull()?.getValue(Field.FIELD_STEPS)?.asInt() ?: 0\n // Do something with totalSteps\n }\n .addOnFailureListener { e -\u003e\n Log.i(TAG, \"There was a problem getting steps.\", e)\n }\n```\n\nThe daily total is computed from midnight of the current day on the device's\ncurrent timezone.\n\nTo get the same daily step count as the Fit app, create a data source using\nthe `com.google.android.gms`app package, as shown in the following example: \n\n```kotlin\nval startTime = LocalDate.now().atStartOfDay(ZoneId.systemDefault())\nval endTime = LocalDateTime.now().atZone(ZoneId.systemDefault())\n\nval datasource = DataSource.Builder()\n .setAppPackageName(\"com.google.android.gms\")\n .setDataType(DataType.TYPE_STEP_COUNT_DELTA)\n .setType(DataSource.TYPE_DERIVED)\n .setStreamName(\"estimated_steps\")\n .build()\n\nval request = DataReadRequest.Builder()\n .aggregate(datasource)\n .bucketByTime(1, TimeUnit.DAYS)\n .setTimeRange(startTime.toEpochSecond(), endTime.toEpochSecond(), TimeUnit.SECONDS)\n .build()\n\nFitness.getHistoryClient(this, GoogleSignIn.getAccountForExtension(this, fitnessOptions))\n .readData(request)\n .addOnSuccessListener { response -\u003e\n val totalSteps = response.buckets\n .flatMap { it.dataSets }\n .flatMap { it.dataPoints }\n .sumBy { it.getValue(Field.FIELD_STEPS).asInt() }\n Log.i(TAG, \"Total steps: $totalSteps\")\n }\n```\n\nFor more information about working with aggregate data sources, see\n[Work with the Fitness History](/fit/android/history).\n\n### REST\n\nYour app can read the current daily step count total across all data\nsources by making a `POST` request and querying the\n`com.google.step_count.delta` data type for the specified time period.\n\n**HTTP method**\n\nPOST\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate\n\n**Request body** \n\n {\n \"aggregateBy\": [{\n \"dataTypeName\": \"com.google.step_count.delta\",\n \"dataSourceId\": \"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps\"\n }],\n \"bucketByTime\": { \"durationMillis\": 86400000 },\n \"startTimeMillis\": 1438705622000,\n \"endTimeMillis\": 1439310422000\n }\n\n**Curl command** \n\n curl \\\n -X POST \\\n -H \"Content-Type: application/json;encoding=utf-8\" \\\n -H \"Authorization: Bearer $ACCESS_TOKEN\" \\\n -d @aggregate.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"]]