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 API

Use 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 deviceUUID to 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

Documentation

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.