SleepSegmentEvent

  • SleepSegmentEvent represents segmented sleep data after the user is awake, with content depending on its status code.

  • If the status is STATUS_SUCCESSFUL or STATUS_MISSING_DATA, the event includes detected sleep start and end times.

  • If the status is STATUS_NOT_DETECTED, the event contains no other information besides the status.

  • Sleep detection results are based on device motion and ambient light readings.

  • You can retrieve sleep start and end times using getStartTimeMillis() and getEndTimeMillis().

public classSleepSegmentEvent extendsObject
implementsParcelable

Represents the result of segmenting sleep after the user is awake. Its contents depend on the status code:

  • If the status code isSTATUS_SUCCESSFUL orSTATUS_MISSING_DATA, then an instance of this class contains a detected sleep start time and a detected sleep end time. These times represent the beginning and end of sleep during a particular day.
  • If the status code isSTATUS_NOT_DETECTED, then an instance of this class contains no other information.

To retrieve any detected sleep start/end times, call getStartTimeMillis() and getEndTimeMillis(), respectively. Note that both of these times are the UNIX epoch time (milliseconds since 1/1/1970 UTC).

The sleep detection result depends on sampled device motion and ambient light readings during the past day. For customized sleep segmentation, useSleepClassifyEvent.

Constant Summary

int STATUS_MISSING_DATASleep segment was detected, but there was some missing data near the detected sleep segment.
int STATUS_NOT_DETECTEDSleep segment is not detected in the past day, or there isn't enough confidence that the user slept during the past day.
int STATUS_SUCCESSFULSuccessfully detected sleep segment in the past day.

Inherited Constant Summary

From interface android.os.Parcelable
intCONTENTS_FILE_DESCRIPTOR
intPARCELABLE_WRITE_RETURN_VALUE

Field Summary

public static finalCreator<SleepSegmentEvent> CREATOR

Public Method Summary

boolean
staticList<SleepSegmentEvent>
extractEvents(Intent intent)
Extracts the list ofSleepSegmentEvent from anIntent.
long
getEndTimeMillis()
If the status is STATUS_SUCCESS or STATUS_MISSING_DATA, this method returns the UNIX epoch time for the moment when the system detects that the user stops sleeping and wakes up.
long
getSegmentDurationMillis()
The amount of elapsed time, in milliseconds, that the system detected that the user was asleep based on the device sensor data.
long
getStartTimeMillis()
If the status is STATUS_SUCCESS or STATUS_MISSING_DATA, this method returns the UNIX epoch time (milliseconds since 1/1/1970 UTC) for the moment when the system detects that the user begins sleeping.
int
getStatus()
Get a status code that indicates whether the system succeeded in detecting sleep and gathering sleep data.
static boolean
hasEvents(Intent intent)
Checks whether theIntent has anySleepSegmentEvent.
int
String
void
writeToParcel(Parcel out, int flags)

Inherited Method Summary

From class java.lang.Object
Object
clone()
boolean
equals(Object arg0)
void
finalize()
finalClass<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
From interface android.os.Parcelable
abstract int
describeContents()
abstract void
writeToParcel(Parcel arg0, int arg1)

Constants

public static final intSTATUS_MISSING_DATA

Sleep segment was detected, but there was some missing data near the detected sleep segment. This could happen for a variety of reasons, including the following: the user turned off their device, the user delayed logging into their device after a system reboot or system upgrade, or an event occurred that paused the detection.

Constant Value:1

public static final intSTATUS_NOT_DETECTED

Sleep segment is not detected in the past day, or there isn't enough confidence that the user slept during the past day. This could happen for a variety of reasons, including the following: too much missing data, the user sleeps with the light, the user interacts with their device often, or the user's device doesn't support the sensors needed for sleep detection.

Constant Value:2

public static final intSTATUS_SUCCESSFUL

Successfully detected sleep segment in the past day.

Constant Value:0

Fields

public static finalCreator<SleepSegmentEvent>CREATOR

Public Methods

public booleanequals(Object o)

public staticList<SleepSegmentEvent>extractEvents(Intent intent)

Extracts the list ofSleepSegmentEvent from anIntent.

Parameters
intenttheIntent to extract from
Returns
  • a list ofSleepSegmentEvents if the intent has events, or an empty list if the intent doesn't contain any events.

public longgetEndTimeMillis()

If the status is STATUS_SUCCESS or STATUS_MISSING_DATA, this method returns the UNIX epoch time for the moment when the system detects that the user stops sleeping and wakes up. If the status is STATUS_NOT_DETECTED, this method returns 0.

Returns
  • the epoch time of the sleep segment end time.

public longgetSegmentDurationMillis()

The amount of elapsed time, in milliseconds, that the system detected that the user was asleep based on the device sensor data. If the status is STATUS_NOT_DETECTED, this method returns 0.

Returns
  • the sleep segment duration in milliseconds.

public longgetStartTimeMillis()

If the status is STATUS_SUCCESS or STATUS_MISSING_DATA, this method returns the UNIX epoch time (milliseconds since 1/1/1970 UTC) for the moment when the system detects that the user begins sleeping. If the status is STATUS_NOT_DETECTED, this method returns 0.

Returns
  • the epoch time of the sleep segment start time

public intgetStatus()

Get a status code that indicates whether the system succeeded in detecting sleep and gathering sleep data.

Returns
  • the status of the sleep segment detection.

public static booleanhasEvents(Intent intent)

Checks whether theIntent has anySleepSegmentEvent.

Parameters
intenttheIntent to extract from
Returns
  • true if the Intent has events

public inthashCode()

publicStringtoString()

public voidwriteToParcel(Parcel out, int flags)

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-10-31 UTC.