I use the Sleep API in my Kotlin Android app. To get sleep data, I am following these steps:
- Getting the
android.permission.ACTIVITY_RECOGNITION
permission from the user - Successfully registering to both SleepSegmentEvent and SleepClassifyEvent
- Listening to events using a Broadcast Receiver
I'm periodically receiving events (testing in an API 30 physical device), but they do not contain SleepSegment or SleepClassify data at all. In fact, incoming intents are completely empty. To illustrate this:
class SleepAPIReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (SleepSegmentEvent.hasEvents(intent)) {
...
} else if (SleepClassifyEvent.hasEvents(intent)) {
...
} else {
// THIS ELSE CLAUSE IS TRIGGERED
}
}
The last "else" is triggered, which is weird considering no events should be received if no data is available (or so I thought). Official examples do not even consider receiving intents with neither SleepSegment nor SleepClassify events.
What could be the source of this problem?