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.
To get started, do the following:
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.