AsleepConfig

1. Initialize Config

Asleep.initAsleepConfig()

  • Initialize the SDK.
initAsleepConfig(
    context: Context, 
    apiKey: String, 
    userId: String?, 
    baseUrl: String?, 
    callbackUrl: String?, 
    service: String?, 
    asleepConfigListener: Asleep.AsleepConfigListener,
    asleepLogger: AsleepLogger?
)
Parameter NameTypeDescription
contextContextEnter ApplicationContext
apiKeyStringEnter the value issued by Generate API key
userIdString?Enter null if there is no initial userId, and enter the userId that has been issued since
baseUrlString?If null, use the default value, enter the proxy server address
callbackUrlString?Enter the url of the server to receive sleep session analysis results
serviceString?your app name
asleepConfigListenerAsleepConfigListenerlistener to receive callback for userId
asleepLoggerAsleepLogger?A listener for receiving SDK log callbacks2.4.2<=SDK

Asleep.ConfigListener

interface AsleepConfigListener {
    fun onSuccess(userId: String?, asleepConfig: AsleepConfig?)
    fun onFail(errorCode: Int, detail: String)
}
  • If success, onSuccess()is called.
Parameter NameTypeDescription
userIdString?Newly issued or entered userId
asleepConfigAsleepConfig?Required set value to use the SDK
  • If failure, onFail() is called.
Parameter NameTypeDescription
errorCodeIntAsleepErrorCode
detailStringerrorCode Message

Asleep.AsleepLogger

interface AsleepLogger {
  fun d(tag: String, msg: String, throwable: Throwable? = null)
  fun e(tag: String, msg: String, throwable: Throwable? = null)
  fun i(tag: String, msg: String, throwable: Throwable? = null)
  fun w(tag: String, msg: String, throwable: Throwable? = null)
}
  • Inside the SDK, it is called when d(debug), e(error), i(info), and w(warn) occur, respectively.
Parameter NameTypeDescription
tagString"[Asleep SDK]"
msgStringlog message
throwableThrowable?A class that represents problems that can occur during SDK execution.

2. Delete User

Asleep.deleteUser()

  • Delete all data of the user, including userId.
fun deleteUser(deleteUserIdListener: DeleteUserIdListener?)
Parameter NameTypeDescription
deleteUserIdListenerDeleteUserIdListener?listener to receive callback for deleted userId

Asleep.DeleteUserIdListener

interface DeleteUserIdListener {
    fun onSuccess(userId: String?)
    fun onFail(errorCode: Int, detail: String)
}
  • If success, onSuccess()is called.
Parameter NameTypeDescription
userIdString?deleted userId
  • If failure, onFail() is called.
Parameter NameTypeDescription
errorCodeIntSee AsleepErrorCode
detailStringerrorCode Message

3. Continue Session

  • Available from v2.3.0
  • Developer mode not supported

Asleep.hasUnfinishedSession()

  • After the foreground service is forcibly terminated and restarted, it checks if there is any session that has not been terminated.
hasUnfinishedSession(context: Context): Boolean
Parameter NameTypeDescription
contextContext?Enter ApplicationContext

Asleep.getSavedAsleepConfig()

  • After the foreground service is forcibly terminated and restarted, it retrieves the previously saved asleepConfig.
getSavedAsleepConfig(context: Context, apiKey: String): AsleepConfig?
Parameter NameTypeDescription
contextContext?Enter ApplicationContext
apiKeyStringEnter the value issued by Generate API key