Sleep

Sleep session

SleepSessionRecord in Health Connect. Check what the API exposes and what to look for when this data is missing or differs between apps.

API contract

Identifier
SleepSessionRecord
Time shape
Interval
Required record fields
endTimemetadatastagesstartTime

Android Developers reference for SleepSessionRecord

Read a known time window

Run this inside a coroutine with an initialized Health Connect client, a start and end instant, and the required read grant. Follow the next-page token when checking a larger time range.

val page = healthConnectClient.readRecords(
    ReadRecordsRequest(
        SleepSessionRecord::class,
        timeRangeFilter = TimeRangeFilter.between(start, end)
    )
)
val records = page.records

Read and paginate Health Connect records

Manifest permissions in the Android documentation

Aggregate metrics (1)
  • SleepSessionRecord.SLEEP_DURATION_TOTAL

What to check when the value is missing

Check that the writing app saved a interval record under SleepSessionRecord and that the reading app has access to it. Start with a recent interval that contains a known record.

For a synthetic record, inspect stages before comparing it with what the reader displays.

Compare the data origin and timestamp before looking at a daily dashboard. Check which of the listed metrics the app uses and which sources contribute to it.

Health Connect data types and feature requirements

Trace a missing night of sleep

Compare with Apple HealthKit

Sleep Analysis sleepAnalysis

Health Connect groups sleep stages under a session. HealthKit sleep categories are separate intervals and in-bed intervals can overlap asleep intervals. Preserve the staging and calculate durations from the stages the display actually uses.

API documentation checked . Examples are developer starting points based on the published API.