SleepTrackingManager

  1. reate manager

Asleep.createSleepTrackingManager

  • 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

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, and onUpload() is called every 30 seconds.
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

Asleep.SleepTrackingManager.startSleepTracking

  • Start Sleep Tracking. If called without parameters, 'isPrivacySensitive' is set to true (recommended).
fun startSleepTracking()
// or
fun startSleepTracking(isPrivacySensitive = true)
Parameter NameTypeDescriptionVersion
isPrivacySensitiveBooleanIf true, PrivacySensitive is enabled; if false, it is disabled2.4.1<=SDK

🚧

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 NameTypeDescription
analysisListenerAnalysisListenersleep 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 breathStages: 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
breathStagesList<Int?>?Breath Stability Stages List
  • If failure, onFail() is called.
Parameter NameTypeDescription
errorCodeIntSee AsleepErrorCode
detailStringerrorCode message

4. Stop sleep tracking

Asleep.SleepTrackingManager.stopSleepTracking

  • Stop Sleep Tracking.
fun stopSleepTracking()

5. Get sleep tracking status

  • Available from v2.1.2

Asleep.SleepTrackingManager.getTrackingStatus()

fun getTrackingStatus(): TrackingStatus

Asleep.SleepTrackingManager.TrackingStatus

class TrackingStatus (var sessionId: String? = null)
Property nameTypeDescription
sessionIdString?Currently tracking session id
Available from the onCreate function of TrackingListener
Valid until the corresponding Session is closed