SleepSessionRecord

class SleepSessionRecord : Record


Captures the user's sleep length and its stages. Each record represents a time interval for a full sleep session.

All sleep stage time intervals should fall within the sleep session interval. Time intervals for stages don't need to be continuous but shouldn't overlap.

Example code demonstrate how to read sleep session:

import androidx.health.connect.client.request.ReadRecordsRequest

val response =
    healthConnectClient.readRecords(
        ReadRecordsRequest<SleepSessionRecord>(
            timeRangeFilter = TimeRangeFilter.between(startTime, endTime)
        )
    )
for (sleepRecord in response.records) {
    // Process each sleep record
}

Summary

Nested types

Captures the sleep stage the user entered during a sleep session.

Constants

const Int

The user is awake and either known to be in bed, or it is unknown whether they are in bed or not.

const Int

The user is awake and in bed.

const Int

The user is in a deep sleep stage.

const Int

The user is in a light sleep stage.

const Int

The user is out of bed and assumed to be awake.

const Int

The user is in a REM sleep stage.

const Int

The user is asleep but the particular stage of sleep (light, deep or REM) is unknown.

const Int

Use this type if the stage of sleep is unknown.

Public companion properties

AggregateMetric<Duration>

Metric identifier to retrieve the total sleep session duration from androidx.health.connect.client.aggregate.AggregationResult.

Public constructors

SleepSessionRecord(
    startTime: Instant,
    startZoneOffset: ZoneOffset?,
    endTime: Instant,
    endZoneOffset: ZoneOffset?,
    title: String?,
    notes: String?,
    stages: List<SleepSessionRecord.Stage>,
    metadata: Metadata
)

Public functions

open operator Boolean
equals(other: Any?)
open Int

Public properties

open Instant

End time of the record.

open ZoneOffset?

User experienced zone offset at endTime, or null if unknown.

open Metadata

Set of common metadata associated with the written record.

String?

Additional notes for the session.

List<SleepSessionRecord.Stage>
open Instant

Start time of the record.

open ZoneOffset?

User experienced zone offset at startTime, or null if unknown.

String?

Title of the session.

Constants

STAGE_TYPE_AWAKE

const val STAGE_TYPE_AWAKE = 1: Int

The user is awake and either known to be in bed, or it is unknown whether they are in bed or not.

STAGE_TYPE_AWAKE_IN_BED

const val STAGE_TYPE_AWAKE_IN_BED = 7: Int

The user is awake and in bed.

STAGE_TYPE_DEEP

const val STAGE_TYPE_DEEP = 5: Int

The user is in a deep sleep stage.

STAGE_TYPE_LIGHT

const val STAGE_TYPE_LIGHT = 4: Int

The user is in a light sleep stage.

STAGE_TYPE_OUT_OF_BED

const val STAGE_TYPE_OUT_OF_BED = 3: Int

The user is out of bed and assumed to be awake.

STAGE_TYPE_REM

const val STAGE_TYPE_REM = 6: Int

The user is in a REM sleep stage.

STAGE_TYPE_SLEEPING

const val STAGE_TYPE_SLEEPING = 2: Int

The user is asleep but the particular stage of sleep (light, deep or REM) is unknown.

STAGE_TYPE_UNKNOWN

const val STAGE_TYPE_UNKNOWN = 0: Int

Use this type if the stage of sleep is unknown.

Public companion properties

SLEEP_DURATION_TOTAL

val SLEEP_DURATION_TOTALAggregateMetric<Duration>

Metric identifier to retrieve the total sleep session duration from androidx.health.connect.client.aggregate.AggregationResult.

Public constructors

SleepSessionRecord

Added in 1.1.0-alpha07
SleepSessionRecord(
    startTime: Instant,
    startZoneOffset: ZoneOffset?,
    endTime: Instant,
    endZoneOffset: ZoneOffset?,
    title: String? = null,
    notes: String? = null,
    stages: List<SleepSessionRecord.Stage> = emptyList(),
    metadata: Metadata = Metadata.EMPTY
)

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

Public properties

endTime

Added in 1.1.0-alpha07
open val endTimeInstant

End time of the record.

endZoneOffset

Added in 1.1.0-alpha07
open val endZoneOffsetZoneOffset?

User experienced zone offset at endTime, or null if unknown. Providing these will help history aggregations results stay consistent should user travel. Queries with user experienced time filters will assume system current zone offset if the information is absent.

metadata

Added in 1.1.0-alpha07
open val metadataMetadata

Set of common metadata associated with the written record.

notes

Added in 1.1.0-alpha07
val notesString?

Additional notes for the session. Optional field.

startTime

Added in 1.1.0-alpha07
open val startTimeInstant

Start time of the record.

startZoneOffset

Added in 1.1.0-alpha07
open val startZoneOffsetZoneOffset?

User experienced zone offset at startTime, or null if unknown. Providing these will help history aggregations results stay consistent should user travel. Queries with user experienced time filters will assume system current zone offset if the information is absent.

title

Added in 1.1.0-alpha07
val titleString?

Title of the session. Optional field.