# SleepSegmentEvent

public class **SleepSegmentEvent** extends [Object](https://developer.android.com/reference/java/lang/Object.html)  
implements [Parcelable](https://developer.android.com/reference/android/os/Parcelable.html) Represents the result of segmenting sleep after the user is awake. Its contents depend on
the status code:

- If the status code is `STATUS_SUCCESSFUL` or `STATUS_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 is `STATUS_NOT_DETECTED`, then an instance of this class contains no other information.

To retrieve any detected sleep start/end times, call `https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#getStartTimeMillis()` and `https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#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, use
`SleepClassifyEvent`.

### Constant Summary

|---|---|---|
| int | [STATUS_MISSING_DATA](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#STATUS_MISSING_DATA) | Sleep segment was detected, but there was some missing data near the detected sleep segment. |
| int | [STATUS_NOT_DETECTED](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#STATUS_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. |
| int | [STATUS_SUCCESSFUL](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#STATUS_SUCCESSFUL) | Successfully detected sleep segment in the past day. |

### Inherited Constant Summary

From interface android.os.Parcelable

|---|---|---|
| int | CONTENTS_FILE_DESCRIPTOR |   |
| int | PARCELABLE_WRITE_RETURN_VALUE |   |

### Field Summary

|---|---|---|
| public static final [Creator](https://developer.android.com/reference/android/os/Parcelable.Creator.html)\<[SleepSegmentEvent](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent)\> | [CREATOR](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#CREATOR) |   |

### Public Method Summary

|---|---|
| boolean | [equals](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#equals(java.lang.Object))([Object](https://developer.android.com/reference/java/lang/Object.html) o) |
| static [List](https://developer.android.com/reference/java/util/List.html)\<[SleepSegmentEvent](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent)\> | [extractEvents](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#extractEvents(android.content.Intent))([Intent](https://developer.android.com/reference/android/content/Intent.html) intent) Extracts the list of `SleepSegmentEvent` from an `Intent`. |
| long | [getEndTimeMillis](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#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](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#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](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#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](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#getStatus())() Get a status code that indicates whether the system succeeded in detecting sleep and gathering sleep data. |
| static boolean | [hasEvents](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#hasEvents(android.content.Intent))([Intent](https://developer.android.com/reference/android/content/Intent.html) intent) Checks whether the `Intent` has any `SleepSegmentEvent`. |
| int | [hashCode](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#hashCode())() |
| [String](https://developer.android.com/reference/java/lang/String.html) | [toString](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#toString())() |
| void | [writeToParcel](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent#writeToParcel(android.os.Parcel,%20int))([Parcel](https://developer.android.com/reference/android/os/Parcel.html) out, int flags) |

### Inherited Method Summary

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | 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](https://developer.android.com/reference/android/os/Parcel.html) arg0, int arg1) |

## Constants

#### public static final int
**STATUS_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 int
**STATUS_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 int
**STATUS_SUCCESSFUL**

Successfully detected sleep segment in the past day.
Constant Value: 0

## Fields

#### public static final [Creator](https://developer.android.com/reference/android/os/Parcelable.Creator.html)\<[SleepSegmentEvent](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent)\>
**CREATOR**

## Public Methods

#### public boolean **equals** ([Object](https://developer.android.com/reference/java/lang/Object.html) o)

#### public static [List](https://developer.android.com/reference/java/util/List.html)\<[SleepSegmentEvent](https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent)\>
**extractEvents** ([Intent](https://developer.android.com/reference/android/content/Intent.html) intent)

Extracts the list of `SleepSegmentEvent` from an `Intent`.

##### Parameters

| intent | the `Intent` to extract from |
|---|---|

##### Returns

- a list of `https://developers.google.com/android/reference/com/google/android/gms/location/SleepSegmentEvent`s if the intent has events, or an empty list if the intent doesn't contain any events.

#### public 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. If the status is STATUS_NOT_DETECTED, this method returns 0.

##### Returns

- the epoch time of the sleep segment end time.

#### public long **getSegmentDurationMillis** ()

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 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. If the status is STATUS_NOT_DETECTED, this method
returns 0.

##### Returns

- the epoch time of the sleep segment start time

#### public int **getStatus** ()

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 boolean **hasEvents** ([Intent](https://developer.android.com/reference/android/content/Intent.html) intent)

Checks whether the `Intent` has any `SleepSegmentEvent`.

##### Parameters

| intent | the `Intent` to extract from |
|---|---|

##### Returns

- true if the Intent has events

#### public int **hashCode** ()

#### public [String](https://developer.android.com/reference/java/lang/String.html) **toString** ()

#### public void **writeToParcel** ([Parcel](https://developer.android.com/reference/android/os/Parcel.html) out, int flags)