2. Initializing the SDK

🚧

Before you begin, make sure you’ve completed these steps:

👍

By the end of this guide you should see the following results:

  • The app will start without errors;
  • Android Studio’s developer console will display a deviceUUID for Mindbox’s SDK;
  • A Mindbox customer profile will be created if you enable this as part of your integration.

1. Selecting the SDK configuration

Follow your Marketing requirements to select a fitting SDK configuration.

🚧

Get a "<project endpoint>" from Mindbox’s Customer Success manager or look it up in the instructions on Setting up Integration Points for an Android App.

📘

Mindbox’s Domain API

Use api.mindbox.cloud to send requests to Mindbox’s API.

❗️Don’t submit your project address here!

How to submit anonymous users to Mindbox and send them push notifications

val configuration = MindboxConfiguration.Builder(
    applicationContext,
    "api.mindbox.cloud",
    "<project endpoint>" )
    .shouldCreateCustomer(true)
    .subscribeCustomerIfCreated(true)
    .build()

How to submit anonymous users to Mindbox without the option to send them push notifications

val configuration = MindboxConfiguration.Builder(
    applicationContext,
    "api.mindbox.cloud",
    "<project endpoint>" )
    .shouldCreateCustomer(true)
    .subscribeCustomerIfCreated(false)
    .build()

If you don’t want to submit anonymous users to Mindbox

val configuration = MindboxConfiguration.Builder(
    applicationContext,
    "api.mindbox.cloud",
    "<project endpoint>" )
    .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).

Using SDK with custom WorkManager initialization

Documentation

The SDK uses WorkManager to send events within Mindbox. If your WorkManager initialization is not automatic but manual, add the following:

Configuration.Builder().setWorkerFactory(
  DelegatingWorkerFactory().apply {
    // your factories
     addFactory(Mindbox.mindboxWorkerFactory)
  }
)
import android.app.Application
import cloud.mindbox.mobile_sdk.*

class MyApp: Application() {
    override fun onCreate() {
        super.onCreate()

                    
                        ENTER THE SDK CONFIGURATION SELECTED AT STEP 1                    

        Mindbox.init(applicationContext, configuration, listOf())

    }
}

If you have a single activity application and cannot initialize the SDK in your app

You can still initialize Mindbox’s SDK in your Activity by passing this Activity context to Mindbox.init.

🚧

To check that the SDK is initialized correctly, add a deviceUUID output anywhere in the console.

We recommend that you output the deviceUUID immediately after you call Mindbox.init.

Launch the app from Android Studio on an actual or simulated device:

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.subscribeDeviceUuid { uuid -> Log.i("MindboxDeviceUUID", uuid) }
    }
}