# SleepSessionRecord

Artifact: [androidx.health.connect:connect-client](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/records/SleepSessionRecord.kt+class:androidx.health.connect.client.records.SleepSessionRecord) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord "View this page in Java")


```
class SleepSessionRecord : Record
```

<br />

*** ** * ** ***

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:

```kotlin
import androidx.health.connect.client.readRecord
import androidx.health.connect.client.records.SleepSessionRecord
import androidx.health.connect.client.request.ReadRecordsRequest
import androidx.health.connect.client.time.TimeRangeFilter

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

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord.Stage` Captures the sleep stage the user entered during a sleep session. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_AWAKE() = 1` The user is awake and either known to be in bed, or it is unknown whether they are in bed or not. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_AWAKE_IN_BED() = 7` The user is awake and in bed. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_DEEP() = 5` The user is in a deep sleep stage. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_LIGHT() = 4` The user is in a light sleep stage. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_OUT_OF_BED() = 3` The user is out of bed and assumed to be awake. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_REM() = 6` The user is in a REM sleep stage. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_SLEEPING() = 2` The user is asleep but the particular stage of sleep (light, deep or REM) is unknown. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_UNKNOWN() = 0` Use this type if the stage of sleep is unknown. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregateMetric<https://developer.android.com/reference/java/time/Duration.html>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#SLEEP_DURATION_TOTAL()` Metric identifier to retrieve the total sleep session duration from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#SleepSessionRecord(java.time.Instant,java.time.ZoneOffset,java.time.Instant,java.time.ZoneOffset,androidx.health.connect.client.records.metadata.Metadata,kotlin.String,kotlin.String,kotlin.collections.List)( startTime: https://developer.android.com/reference/java/time/Instant.html, startZoneOffset: https://developer.android.com/reference/java/time/ZoneOffset.html?, endTime: https://developer.android.com/reference/java/time/Instant.html, endZoneOffset: https://developer.android.com/reference/java/time/ZoneOffset.html?, metadata: https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata, title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, notes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, stages: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord.Stage> )` |

| ### Public functions |
|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#hashCode()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#toString()()` |

| ### Public properties |
|---|---|
| `open https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#endTime()` End time of the record. |
| `open https://developer.android.com/reference/java/time/ZoneOffset.html?` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#endZoneOffset()` User experienced zone offset at `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/IntervalRecord#endTime()`, or null if unknown. |
| `open https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/metadata/Metadata` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#metadata()` Set of common metadata associated with the written record. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#notes()` Additional notes for the session. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord.Stage>` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#stages()` |
| `open https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#startTime()` Start time of the record. |
| `open https://developer.android.com/reference/java/time/ZoneOffset.html?` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#startZoneOffset()` User experienced zone offset at `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/IntervalRecord#startTime()`, or null if unknown. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/SleepSessionRecord#title()` 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_TOTAL: AggregateMetric<Duration>
```

Metric identifier to retrieve the total sleep session duration from `https://developer.android.com/reference/kotlin/androidx/health/connect/client/aggregate/AggregationResult`.

## Public constructors

### SleepSessionRecord

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

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

## Public functions

### equals

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

### hashCode

```
open fun hashCode(): Int
```

### toString

```
open fun toString(): String
```

## Public properties

### endTime

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
open val endTime: Instant
```

End time of the record.

### endZoneOffset

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
open val endZoneOffset: ZoneOffset?
```

User experienced zone offset at `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/IntervalRecord#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

```
open val metadata: Metadata
```

Set of common metadata associated with the written record.

### notes

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
val notes: String?
```

Additional notes for the session. Optional field.

### stages

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
val stages: List<SleepSessionRecord.Stage>
```

### startTime

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
open val startTime: Instant
```

Start time of the record.

### startZoneOffset

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
open val startZoneOffset: ZoneOffset?
```

User experienced zone offset at `https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/IntervalRecord#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](https://developer.android.com/jetpack/androidx/releases/health-connect#1.1.0)

```
val title: String?
```

Title of the session. Optional field.