SleepTrackingManager
1. Create manager
Asleep.createSleepTrackingManager
Create SleepTrackingManager that manages Sleep Tracking Feature
fun createSleepTrackingManager(
asleepConfig: AsleepConfig?,
trackingListener: SleepTrackingManager.TrackingListener
): SleepTrackingManager?
Parameter Name | Type | Description |
---|---|---|
asleepConfig | AsleepConfig? | Enter the set value received by the callback in the initAsleepConfig call |
trackingListener | TrackingListener | Listener to receive callback status for Sleep Tracking |
Asleep.SleepTrackingManager.TrackingListener
interface TrackingListener {
fun onCreate()
fun onUpload(sequence: Int)
fun onClose(sessionId: String)
fun onFail(errorCode: Int, detail: String)
}
When Sleep Tracking starts, onCreate () is called.
- If Sleep Tracking succeeds in 30 seconds, onUpload () is called.
Parameter Name | Type | Description |
---|---|---|
sequence | Int | A value that starts from 0 and increases by 1 every 30 seconds |
- When Sleep Tracking is ended, onClose()is called.
Parameter Name | Type | Description |
---|---|---|
sessionId | String | Report Result id value |
- If failure, onFail() is called.
Parameter Name | Type | Description |
---|---|---|
errorCode | Int | See AsleepErrorCode |
detail | String | errorCode Message |
2. Start sleep tracking
Asleep.SleepTrackingManager.startSleepTracking
Start Sleep Tracking.
fun startSleepTracking()
Follow the guideline for testing the sleep tracking
To accurately test Asleep's sleep tracking/analysis, please follow the test environment guide. Please note that sleep analysis results obtained in environments not adhering to this guide may not accurately reflect actual sleep patterns.
🔗 Check Test Environment Guideline
3. Sleep Analysis
Asleep.SleepTrackingManager.requestAnalysis()
We receive the results measured to date.
fun requestAnalysis(analysisListener: SleepTrackingManager.AnalysisListener)
Parameter Name | Type | Description |
---|---|---|
analysisListener | AnalysisListener | sleep analysis listener |
Asleep.SleepTrackingManager.AnalysisListener
interface AnalysisListener {
fun onSuccess(session: Session)
fun onFail(errorCode: Int, detail: String)
}
- If success, onSuccess() is called.
Session data type
data class Session(
val id: String?,
val state: String?,
val startTime: String?,
val endTime: String?,
val sleepStages: List<Int?>?,
val osaStages: List<Int?>?
)
Parameter Name | Type | Description |
---|---|---|
id | String? | Sleep session id |
state | String? | Sleep session state (OPEN, CLOSED or COMPLETE) |
startTime | String? | Session start time |
endTime | String? | Session end date |
sleepStages | List<Int?>? | Sleep stages |
osaStages | List<Int?>? | Sleep apnea stages |
- If failure, onFail() is called.
Parameter Name | Type | Description |
---|---|---|
errorCode | Int | SeeAsleepErrorCode |
detail | String | errorCode message |
4. Stop sleep tracking
Asleep.SleepTrackingManager.stopSleepTracking
Stop Sleep Tracking.
fun stopSleepTracking()
Updated over 1 year ago