Low-Power Sleep Tracking on Android
Posted by Nick Grayson, Product Manager
Android works best when it helps developers create apps that people love. That’s why we are dedicated to providing useful APIs like Activity Recognition which, with the user’s permission, can detect user’s activities (such as whether a user is biking or walking) to help apps provide contextually aware experiences.
So much of what we do relies on a good night's rest. Our phones have become great tools for making more informed decisions about our sleep. And by being informed about sleep habits, people can make better decisions throughout the day about sleep, which affects things like concentration and mental health.
In an effort to help our users stay informed about their sleep, we are making our Sleep API publicly available.
What is the Sleep API?
The Sleep API is an Android Activity Recognition API that surfaces information about the user’s sleep. It can be used to power features like the Bedtime mode in Clock .
This sleeping information is reported in two ways:
A ‘sleep confidence’, which is reported at a regular interval (up to 10 minutes)
A daily sleep segment which is reported after a wakeup is detected
The API uses an on-device artificial intelligence model that uses the device’s light and motion sensors as inputs.
As with all of our Activity Recognition APIs, the app must be granted the Physical Activity Recognition runtime permission from the user to detect sleep.
Why is this important for developers?
Developers spend valuable engineering time to combine sensor signals to determine when the user has started or ended activities like sleep. These detection algorithms are inconsistent between apps and when multiple apps independently and continuously check for changes in user activity, battery life suffers.
The Sleep API is a simple API that centralizes sleep detection processing in a battery-efficient manner. For this launch, we are proud to collaborate with Urbandroid, the developer of the popular alarm app, Sleep As Android
Sleep as Android is a swiss army knife for getting a better night’s rest. It tracks sleep duration, regularity, phases, snoring, and more. Sleep Duration is one of the most important parameters to watch for ensuring a good night’s rest. The new Sleep API gives us a fantastic opportunity to track it automatically in the most battery efficient way imaginable.
- Sleep as Android Team
When can I start using this API?
The Sleep API is available for developers to use now as part of the latest version of Google Play Services .
This API is one step of our efforts to help our users get a better night's rest. We look forward to working more on this API and in this area in the future.
If you are interested in exploring or using this API, check out our API Documentation .