These docs are for v1.0. Click to read the latest docs for v2.0.


1. Create manager


Create SleepTrackingManager that manages Sleep Tracking Feature

fun createSleepTrackingManager(
    asleepConfig: AsleepConfig?, 
    trackingListener: SleepTrackingManager.TrackingListener
): SleepTrackingManager?
Parameter NameTypeDescription
asleepConfigAsleepConfig?Enter the set value received by the callback in the initAsleepConfig call
trackingListenerTrackingListenerListener to receive callback status for Sleep Tracking


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 NameTypeDescription
sequenceIntA value that starts from 0 and increases by 1 every 30 seconds
  • When Sleep Tracking is ended, onClose()is called.
Parameter NameTypeDescription
sessionIdStringReport Result id value
  • If failure, onFail() is called.
Parameter NameTypeDescription
errorCodeIntSee AsleepErrorCode
detailStringerrorCode Message

2. Start sleep tracking


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


We receive the results measured to date.

fun requestAnalysis(analysisListener: SleepTrackingManager.AnalysisListener)
Parameter NameTypeDescription
analysisListenerAnalysisListenersleep analysis listener


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 NameTypeDescription
idString?Sleep session id
stateString?Sleep session state (OPEN, CLOSED or COMPLETE)
startTimeString?Session start time
endTimeString?Session end date
sleepStagesList<Int?>?Sleep stages
osaStagesList<Int?>?Sleep apnea stages
  • If failure, onFail() is called.
Parameter NameTypeDescription
detailStringerrorCode message

4. Stop sleep tracking


Stop Sleep Tracking.

fun stopSleepTracking()