# 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)

*** ** * ** ***


```
public final class SleepSessionRecord implements 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 |
|---|
| `public final class https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord.Stage` Captures the sleep stage the user entered during a sleep session. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/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. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_AWAKE_IN_BED() = 7` The user is awake and in bed. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_DEEP() = 5` The user is in a deep sleep stage. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_LIGHT() = 4` The user is in a light sleep stage. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_OUT_OF_BED() = 3` The user is out of bed and assumed to be awake. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_REM() = 6` The user is in a REM sleep stage. |
| `static final int` | `https://developer.android.com/reference/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. |
| `static final int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#STAGE_TYPE_UNKNOWN() = 0` Use this type if the stage of sleep is unknown. |

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/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)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Instant.html startTime, https://developer.android.com/reference/java/time/ZoneOffset.html startZoneOffset, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Instant.html endTime, https://developer.android.com/reference/java/time/ZoneOffset.html endZoneOffset, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/health/connect/client/records/metadata/Metadata metadata, https://developer.android.com/reference/java/lang/String.html title, https://developer.android.com/reference/java/lang/String.html notes, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord.Stage> stages )` |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getEndTime()()` End time of the record. |
| `https://developer.android.com/reference/java/time/ZoneOffset.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getEndZoneOffset()()` User experienced zone offset at `https://developer.android.com/reference/androidx/health/connect/client/records/IntervalRecord#endTime()`, or null if unknown. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/health/connect/client/records/metadata/Metadata` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getMetadata()()` Set of common metadata associated with the written record. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getNotes()()` Additional notes for the session. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord.Stage>` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getStages()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/time/Instant.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getStartTime()()` Start time of the record. |
| `https://developer.android.com/reference/java/time/ZoneOffset.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getStartZoneOffset()()` User experienced zone offset at `https://developer.android.com/reference/androidx/health/connect/client/records/IntervalRecord#startTime()`, or null if unknown. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#getTitle()()` Title of the session. |
| `int` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#hashCode()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/health/connect/client/records/SleepSessionRecord#toString()()` |

## Constants

### STAGE_TYPE_AWAKE

```
public static final int 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.

### STAGE_TYPE_AWAKE_IN_BED

```
public static final int STAGE_TYPE_AWAKE_IN_BED = 7
```

The user is awake and in bed.

### STAGE_TYPE_DEEP

```
public static final int STAGE_TYPE_DEEP = 5
```

The user is in a deep sleep stage.

### STAGE_TYPE_LIGHT

```
public static final int STAGE_TYPE_LIGHT = 4
```

The user is in a light sleep stage.

### STAGE_TYPE_OUT_OF_BED

```
public static final int STAGE_TYPE_OUT_OF_BED = 3
```

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

### STAGE_TYPE_REM

```
public static final int STAGE_TYPE_REM = 6
```

The user is in a REM sleep stage.

### STAGE_TYPE_SLEEPING

```
public static final int STAGE_TYPE_SLEEPING = 2
```

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

### STAGE_TYPE_UNKNOWN

```
public static final int STAGE_TYPE_UNKNOWN = 0
```

Use this type if the stage of sleep is unknown.

## Public fields

### SLEEP_DURATION_TOTAL

```
public static final @NonNull AggregateMetric<@NonNull Duration> SLEEP_DURATION_TOTAL
```

Metric identifier to retrieve the total sleep session duration from `https://developer.android.com/reference/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)

```
public SleepSessionRecord(
    @NonNull Instant startTime,
    ZoneOffset startZoneOffset,
    @NonNull Instant endTime,
    ZoneOffset endZoneOffset,
    @NonNull Metadata metadata,
    String title,
    String notes,
    @NonNull List<@NonNull SleepSessionRecord.Stage> stages
)
```

## Public methods

### equals

```
public boolean equals(Object other)
```

### getEndTime

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

```
public @NonNull Instant getEndTime()
```

End time of the record.

### getEndZoneOffset

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

```
public ZoneOffset getEndZoneOffset()
```

User experienced zone offset at `https://developer.android.com/reference/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.

### getMetadata

```
public @NonNull Metadata getMetadata()
```

Set of common metadata associated with the written record.

### getNotes

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

```
public final String getNotes()
```

Additional notes for the session. Optional field.

### getStages

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

```
public final @NonNull List<@NonNull SleepSessionRecord.Stage> getStages()
```

### getStartTime

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

```
public @NonNull Instant getStartTime()
```

Start time of the record.

### getStartZoneOffset

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

```
public ZoneOffset getStartZoneOffset()
```

User experienced zone offset at `https://developer.android.com/reference/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.

### getTitle

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

```
public final String getTitle()
```

Title of the session. Optional field.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```