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 Name | Type | Description | |
---|---|---|---|
context | Context | Enter ApplicationContext | |
apiKey | String | Enter the value issued by Generate API key | |
userId | String? | Enter null if there is no initial userId, and enter the userId that has been issued since | |
baseUrl | String? | If null, use the default value, enter the proxy server address | |
callbackUrl | String? | Enter the url of the server to receive sleep session analysis results | |
service | String? | your app name | |
asleepConfigListener | AsleepConfigListener | listener to receive callback for userId | |
asleepLogger | AsleepLogger? | A listener for receiving SDK log callbacks | 2.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 Name | Type | Description |
---|---|---|
userId | String? | Newly issued or entered userId |
asleepConfig | AsleepConfig? | Required set value to use the SDK |
- If failure, onFail() is called.
Parameter Name | Type | Description |
---|---|---|
errorCode | Int | AsleepErrorCode |
detail | String | errorCode 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 Name | Type | Description |
---|---|---|
tag | String | "[Asleep SDK]" |
msg | String | log message |
throwable | Throwable? | 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 Name | Type | Description |
---|---|---|
deleteUserIdListener | DeleteUserIdListener? | 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 Name | Type | Description |
---|---|---|
userId | String? | deleted userId |
- If failure, onFail() is called.
Parameter Name | Type | Description |
---|---|---|
errorCode | Int | See AsleepErrorCode |
detail | String | errorCode Message |
3. Continue Session
- Available from v2.3.0
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 Name | Type | Description |
---|---|---|
context | Context? | 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 Name | Type | Description |
---|---|---|
context | Context? | Enter ApplicationContext |
apiKey | String | Enter the value issued by Generate API key |
Updated 2 months ago