SleepSessionRecord
public final class SleepSessionRecord implements 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.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 SleepSessionRecord.StageCaptures the sleep stage the user entered during a sleep session. |
Constants |
|
|---|---|
static final int |
STAGE_TYPE_AWAKE = 1The user is awake and either known to be in bed, or it is unknown whether they are in bed or not. |
static final int |
The user is awake and in bed. |
static final int |
STAGE_TYPE_DEEP = 5The user is in a deep sleep stage. |
static final int |
STAGE_TYPE_LIGHT = 4The user is in a light sleep stage. |
static final int |
The user is out of bed and assumed to be awake. |
static final int |
STAGE_TYPE_REM = 6The user is in a REM sleep stage. |
static final int |
The user is asleep but the particular stage of sleep (light, deep or REM) is unknown. |
static final int |
Use this type if the stage of sleep is unknown. |
Public fields |
|
|---|---|
static final @NonNull AggregateMetric<@NonNull Duration> |
Metric identifier to retrieve the total sleep session duration from |
Public constructors |
|---|
SleepSessionRecord( |
Public methods |
|
|---|---|
boolean |
|
@NonNull Instant |
End time of the record. |
ZoneOffset |
User experienced zone offset at |
@NonNull Metadata |
Set of common metadata associated with the written record. |
final String |
getNotes()Additional notes for the session. |
final @NonNull List<@NonNull SleepSessionRecord.Stage> |
|
@NonNull Instant |
Start time of the record. |
ZoneOffset |
User experienced zone offset at |
final String |
getTitle()Title of the session. |
int |
hashCode() |
@NonNull String |
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_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_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 androidx.health.connect.client.aggregate.AggregationResult.
Public constructors
SleepSessionRecord
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
getEndZoneOffset
public ZoneOffset getEndZoneOffset()
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.
getMetadata
public @NonNull Metadata getMetadata()
Set of common metadata associated with the written record.
getNotes
public final String getNotes()
Additional notes for the session. Optional field.
getStartZoneOffset
public ZoneOffset getStartZoneOffset()
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.