Init SDK
Overview
The SDK has to be initialized before use. First initialization will trigger SDK to register online. Therefore, you have to make sure your device being connected before first initialization.
Methods
MPoCAPI.initSdk
This is a async function including callback. You can use
suspendCoroutine
to convert it to a "sync" call mode.
Initializes the MPoC SDK. This method should be called each time the application starts up (for example, in the
Application
's onCreate
). First call will trigger SDK to do online registration.
Parameters
Name | Type | Condition | Description |
---|---|---|---|
license | String | Required | The name of the license file. |
context | Application | Required | The application instance |
autoRegister | Boolean | Optional | true makes SDK register automatically. false disable online registration. only initialize the sdk |
callback | (MPoCResult<SdkInitResult>) -> Unit | Required | The callback to handle the result of the SDK initialization. |
Returns
Return Type | Description |
---|---|
MPoCResult<SdkInitResult> | A wrapped result containing the SDKInitResult. |
data class SdkInitResult(
val isRegistered: Boolean ,// indicate if it is registered
val sdkId: String, // sdkid
val sdkBuildModel: String, // sdk build model
val sdkVersion: String, // sdk version number
val licenseId: String, // license id
val customerId: String, // customer id
)
Usage
suspend fun registerSdk() = suspendCoroutine { continuation ->
MPoCAPI.initSdk(licenseName,this.application) {
when (it) {
is MPoCResult.Failure -> {
Log.d(
"TAG",
"sdk registration fails ${it.code} ${it.message} context=${it.contextual}"
)
continuation.resumeWith(Result.failure<SdkInitResult>(Exception(it.contextual)))
}
is MPoCResult.Success -> {
Log.d("TAG", "register success $it")
continuation.resumeWith(Result.success<SdkInitResult>(it.data))
}
}
}
}
// Success(value=SdkInitResult(isRegistered=true,sdkVersion=1.10.105.12.17,
// sdkId=4411be126c0c91b7, sdkBuildModel="DEBUG", licenseId="1234567890", customerId="1234567890"))