Help users understand their sleep habits

The Sleep API allows apps to determine when the user goes to sleep and wakes up.

After receiving permission from the user, Google Play services collects information related to surrounding brightness, device movement, and more to infer the times when the user falls asleep and wakes up. Your app can subscribe to updates to this information. That way, your app can inform users about their sleep habits and help encourage users to improve their sleep hygiene and overall well-being.

Get started

To get started, do the following:

  1. Target Android 10 (API level 29) or higher.
  2. Request the ACTIVITY_RECOGNITION permission.
  3. Register for updates to the user's sleep behavior, including sleep segments and sleep event classification results, by calling requestSleepSegmentUpdates().

Learn more about the Sleep API

Your app can retrieve information about sleep time from the daily sleep segment update event.

Each sleep segment event contains information about whether the API detected sleep or could detect sleep. The segment event also includes the times when the user most likely fell asleep and woke up, based on available sensor data.

Your app can also receive regular updates about sleep classification events.

Each sleep classification event provides a timestamp, along with values that represent device motion, environment brightness, and the likelihood that the user is asleep at that time. For example, if the sleep confidence significantly increases between one timestamp and the next timestamp, and if the surrounding brightness significantly decreases between those same 2 timestamps, then it's likely that the user recently fell asleep.

Your app can combine this information with additional user-provided data to more confidently determine when the user falls asleep and wakes up.

The SleepSampleKotlin sample app demonstrates an end-to-end workflow using the Sleep API.