Initializing the SDK [Android]
Before you begin, make sure you’ve completed these steps:
Expected result of the “Initializing the SDK [Android]” step:
- The app launches without errors;
- The Mindbox SDK deviceUUID is displayed in the Android Studio console.
- Additionally, only if your integration includes creating and subscribing an anonymous user in Maestra, a Maestra customer profile will be created.
1. Selecting the SDK configuration
Follow your Marketing requirements to select a fitting SDK configuration.
Get a
"<project endpoint ID>"from your Maestra Forward Deployed Marketer or find it in the integration point settings.
Keep in mind that the"<project endpoint>"is case-sensitive. Incorrect casing will result in request errors.
Maestra’s Domain APIUse api.maestra.io to send requests to Maestra’s API.
I want to submit anonymous users to Maestra and send them push notifications:
val configuration = MindboxConfiguration.Builder(
applicationContext,
"api.maestra.io",
"<project endpoint ID>" )
.shouldCreateCustomer(true)
.subscribeCustomerIfCreated(true)
.build()I want to submit anonymous users to Maestra without sending them push notifications:
val configuration = MindboxConfiguration.Builder(
applicationContext,
"api.maestra.io",
"<project endpoint ID>" )
.shouldCreateCustomer(true)
.subscribeCustomerIfCreated(false)
.build()I don't want to submit anonymous users to Maestra:
val configuration = MindboxConfiguration.Builder(
applicationContext,
"api.maestra.io",
"<project endpoint ID>" )
.shouldCreateCustomer(false)
.build()2. Initializing the SDK
To ensure the SDK runs properly, automatic initialization must not be disabled for all components. Make sure that your manifest does not contain this entry:
Disable automatic initialization for all components.If disabled for all components, enable automatic initialization and disable it only for specific components.
Please note that Async SDK initialization may lead to errors.
Initialize the SDK in sync with the Application.onCreate method using the configuration specified in the first step (Selecting SDK Configuration).
To initialize the SDK pass your app’s application to the Mindbox.init method.
import android.app.Application
import cloud.mindbox.mobile_sdk.*
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
// Insert the SDK configuration selected in Step 1 here.
Mindbox.init(application, configuration, listOf())
}
}If you have a single-activity application and cannot initialize the SDK in Application,
You can initialize Mindbox SDK in your Activity by passing this Activity to Mindbox.init.
class MainActivity() : Activity() {
override fun onCreate() {
super.onCreate()
// Insert the SDK configuration selected in Step 1 here.
Mindbox.init(this@MainActivity, configuration, listOf())
}
}If you have already initialized the SDK
You need to replace the deprecated Mindbox.init(context, configuration, list) initialization method (which requires a Context) with one of the new options:
- which requires an application when the SDK is initialized inside the Application class;
- which requires an activity when the SDK is initialized inside an Activity class.
To verify that the SDK is initialized correctly, log the
deviceUUIDto the console at any convenient place.
Next, run the app from Android Studio on a physical device or an emulator.
package cloud.mindbox.checkguidandroid
import android.app.Application
import android.util.Log
import cloud.mindbox.mobile_sdk.*
class MyApp: Application() {
override fun onCreate() {
super.onCreate()
...
Mindbox.init(
application = this,
configuration = configuration,
pushServices = listOf(MindboxFirebase, MindboxHuawei)
)
Mindbox.subscribeDeviceUuid { uuid -> Log.i("MindboxDeviceUUID", uuid) }
}
}Using SDK with custom WorkManager initialization
The Mindbox SDK uses WorkManager to send events.
If automatic WorkManager initialization is disabled in your project and you initialize it manually, add the following:
Configuration.Builder().setWorkerFactory(
DelegatingWorkerFactory().apply {
// your facrories
addFactory(Mindbox.mindboxWorkerFactory)
}
)If You Need to Change the Integration point
If your app is used in multiple countries and the user's actual location becomes known only after the app launches, you may need to update the endpoint to ensure correct country-specific data handling. To do this, call Mindbox.shared.initialization again and provide a new endpoint value in the configuration.
Updated 2 months ago

