Android SDK Methods

Initialization methods

init

Call this method to initialize the SDK. To call init, use the onCreate method for a class inherited from Application.

Mindbox.init(
context: Context,
configuration: MindboxConfiguration,
listOf: List<MindboxPushService>
)

Available options:

  • No mobile push notifications: Mindbox.init(applicationContext, configuration, listOf())
  • Firebase-only: Mindbox.init(applicationContext, configuration, listOf(MindboxFirebase))
  • Huawei-only: Mindbox.init(applicationContext, configuration, listOf(MindboxHuawei))
  • Both Firebase and Huawei: with both services available on a customer’s device, the first one listed is chosen: Mindbox.init(applicationContext, configuration, listOf(MindboxFirebase, MindboxHuawei))

updatePushToken

Call this method to transmit the FMS token to the SDK. To call updatePushToken, use the onNewToken method for a class inherited from FirebaseMessagingService.

Mindbox.updatePushToken(token: String)
class MindboxMessagingService:FirebaseMessagingService() {
    override fun onNewToken(token: String) {
        Mindbox.updateFmsToken(applicationContext, token)
    }
}

Getting data using the SDK

subscribeDeviceUuid and disposeDeviceUuidSubscription

subscribeDeviceUuid

Call this method to return a deviceUUID as a string in the callback. This method requires a subscription to avoid any issues if called before the initialization of Mindbox’s SDK.

The ID returned by the subscribeDeviceUuid method can be used to unsubscribe from the callback.

Mindbox.subscribeDeviceUuid(
  context: Context,
  subscription: (String) → Unit
): String

Mindbox.disposeDeviceUuidSubscription(
  subscriptionId: String
)
val mySubscriptionid = Mindbox.subscribeDeviceUuid {
  deviceUUID -> Log.println(Log.INFO, "MindboxDeviceUUID", deviceUUID)
  }

Mindbox.disposeDeviceUuidSubscription(mySubscriptionid)

disposeDeviceUuidSubscription

Call this method to unsubscribe from deviceUUID. This method accepts the ID returned by the subscription method.

subscribeToken and disposeFmsTokenSubscription

subscribeToken

Call this method to get the FMS or HMS token. The subscribeToken method requires subscription to avoid any issues if called before initializing Mindbox’s SDK.

The method returns a value as a string in a passed callback. The subscribeToken method call returns an ID to unsubscribe from a callback.

Mindbox.subscribeToken(
  subscription: (String?) → Unit
): String
  
Mindbox.disposeTokenSubscription(
  subscriptionId: String
)
val mySubscriptionid = Mindbox.subscribeToken {
  deviceUUID -> Log.println(Log.INFO, "Mindbox Push Token", deviceUUID)
  }

Mindbox.disposeTokenSubscription(mySubscriptionid)

disposeFmsTokenSubscription

Call this method to unsubscribe from the FMS token. The method accepts the ID returned by the subscription method.

getFmsTokenSaveDate

Call this method to retrieve the saving date of the FMS token.

Mindbox.getFmsTokenSaveDate(): String

getSdkVersion

Call this method to return an SDK version.

Mindbox.getSdkVersion(): String

Submitting statistics on a push notification

onPushReceived

Call this method to submit the "Push received" status. The method is used in the push processing code.

Mindbox.onPushReceived(
  context: Context,
  uniqKey: String
)
class MindboxMessagingService:FirebaseMessagingService() {

  override fun onMessageReceived(remoteMessage: RemoteMessage) {

    val data = remoteMessage.data
    val uniqueKey = data["uniqueKey"]

    if (uniqueKey != null) {
      Mindbox.onPushReceived(applicationContext, uniqueKey)
    }
  }

onPushClicked

Call this method to transmit a click on the push notification.

uniq_push_key — mandatory — a push notification ID
uniq_push_button_key — optional — a button ID transmitted when the button is clicked

Mindbox.onPushClicked(
  context: Context,
  uniq_push_key: String,
  uniq_push_button_key: String
)
fun handleIntent(intent: Intent) {
  val uniqKey = intent.getStringExtra("uniqKey");
  val buttonUniqKey = intent.getStringExtra("buttonUniqKey"); 

  if (uniqKey != null) {
    if (uniqKey != buttonUniqKey) {
      Mindbox.onPushClicked(applicationContext, uniqKey, buttonUniqKey  )
      }
    Mindbox.onPushClicked(applicationContext, uniqKey, ""  )
    } 
}

Log Management

The setLoglevel method sets the logging level to manage what Mindbox’s SDK records in the console.

Available values:

Level.NONE
Level.VERBOSE
Level.INFO
Level.DEBUG
Level.WARN
Level.ERROR

Logs are written in a debug build only. In the production environment, Mindbox’s SDK doesn’t write anything in the console.

Mindbox.setLogleve(level)

Transmitting events

To pass events to Mindbox, use the operations added to the admin panel of your project. You can run these operations in two modes:

  • async: once Mindbox receives data, Mindbox’s API returns the 200 status, and then processes data in the background,
  • sync: once Mindbox receives data, Mindbox’s API immediately starts processing the data and returns the actual processing status.

executeAsyncOperation

Call this method to execute async operations.

Mindbox.executeAsyncOperation(
  context = context,
  operationSystemName = "<system name of operation>",
  operationBody = <request body>
)

executeSyncOperation

Call this method to execute synced operations. The results are returned via callbacks.

Mindbox.executeSyncOperation(
  context: Context,
  operationSystemName: "<system name of operation>",
  operationBody: <request body>,
  onSuccess: (OperationResponse) -> Unit,
  onError: (MindboxError) -> Unit
)
Mindbox.executeSyncOperation(context: Context,
    operationSystemName: "<system name of operation>",
    operationBody: <request body>,
    classOfV: Class<V>,
    onSuccess: (V) -> Unit,
    onError: (MindboxError) -> Unit
): Unit

Retrieving clicked push notification data

To process a push notification click, you can retrieve data from a push if its notification was generated using the handleRemoteMessage method.

getUrlFromPushIntent

Call this method to retrieve the URL of the clicked push notification.

The getUrlFromPushIntent method returns the URL specified in the admin panel of your project. When a user clicks a push body, the method returns the URL of the push body. When a user clicks a button, the method returns the URL of the button.

Mindbox.getUrlFromPushIntent(intent)

getPayloadFromPushIntent

Call this method to retrieve the payload of the clicked push notification. The method returns the data specified as the push payload in the admin panel.

The data is returned as a string. If JSON was specified, you have to serialize it on your side.

Mindbox. getPayloadFromPushIntent(intent)