Read data (steps)

Stay organized with collections Save and categorize content based on your preferences.

The Steps data type in Health Connect captures the number of steps a user has taken between readings. Step counts represent a common measurement across health, fitness, and wellness platforms. Health Connect makes it easy to read, write, and insert step count data.

Here’s an example of reading step count data for a user in a time interval:

suspend fun readStepsByTimeRange(
    healthConnectClient: HealthConnectClient,
    startTime: Instant,
    endTime: Instant
) {
    val response =
                timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
    for (stepRecord in response.records) {
        // Process each step record

Reading with Health Connect

Reading data with Health Connect is restricted to applications running in the foreground. This restriction is in place to further strengthen user privacy. It notifies and assures users that Health Connect does not have background read access to their data and that data is only read and accessed in the foreground.

For situations in which being interrupted is expected, such as displaying a reading in your application, read directly from Health Connect to your client application.

For situations in which you may prefer not to be interrupted, such as reading a range of data from Health Connect then writing and uploading it elsewhere, use a ForegroundService, rather than an Activity where it can easily be dismissed.