Skip to main content

Android SDK

Ensure you have completed the Prerequisites section before continuing.

Installation

  1. Add Maven Central repository to your settings.gradle file:

    settings.gradle
    dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
    // ...
    mavenCentral()
    }
    }
  2. Add dashx-android as a dependency in your module-level build.gradle file:

    app/build.gradle
    dependencies {
    // ...
    implementation 'com.dashx:dashx-android:1.0.9'
    }
  3. Enable Java 1.8 source compatibility if you haven't yet.

    app/build.gradle
    android {
    compileOptions {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
    }
    }
tip

If you're using Android Studio, you should hit the Sync Now button that pops up after modifying build.gradle.

Configuration

DashX needs to be initialized as early as possible in your application's lifecycle, which is generally in an instance of the Android Application class:

app/src/main/application/MyApplication.kt
import android.app.Application;
import com.dashx.sdk.DashX;

public class MyApplication extends Application {
public void onCreate() {
super.onCreate();

DashX.configure(
context = this,
publicKey = "...", // required
baseURI = "...", // optional
targetEnvironment = "...", // optional
)
}
}

If your product uses multiple environments, a good practice is to:

Permissions

By default, the dashx-android SDK automatically requests the following permissions:

<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

If you need to meet certain privacy restrictions (example: if your app targets children), you can easily remove the AD_ID permission declaration in your Android Manifest file:

app/src/main/AndroidManifest.xml
<!-- Ensure that xmlns:tools is declared in your manifest tag -->
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="..."
>

<!-- Remove the permission from your final merged manifest -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove" />

Publishing

On the Play Store Console, you will need to fill out the Advertising ID form to prevent any warnings during release:

  • Head to the Policy > App Content section in the sidebar.
    App Content
  • Hit Start under the Advertising ID section.
    Advertising ID
  • For the question, "Does your app use advertising ID?", select the answer "Yes".
  • For the question, "Why does your app need to use advertising ID?", select the option "Analytics".

Troubleshooting

As an optional step, you can set the log level for debugging your integration:

import com.dashx.sdk.DashXLog

// ...

DashXLog.setLogLevel(DashXLog.LogLevel.DEBUG)

By default, the log level is set to ERROR. You can set it to one of: DEBUG (most logs), INFO, ERROR or OFF (no logs).

Usage

User Management

DashX.identify(hashMapOf(
"uid" to "123",
"firstName" to "John",
"lastName" to "Doe"
))

Learn more

Analytics

DashX.track("Button Clicked", hashMapOf(
"label" to "Click here",
"placement" to "top"
))

Learn more

Messaging

// Subscribe to Push Notifications

DashX.subscribe()

DashX.unsubscribe()

// Manage User Preferences

DashX.fetchStoredPreferences(onSuccess = {
// ...
}, onError = {
// ...
})

DashX.saveStoredPreferences(preferenceData, onSuccess = {
// ...
}, onError = {
// ...
})

Learn more

CMS

DashX.fetchContent("email/welcome", language = "en_US", onSuccess = {
println(it)
}, onError = {
println(it)
})

fetchContent accepts following arguments

NameTypeExample
previewBoolean
languageString"en_US"
fieldsList<String>["character", "cast"]
includeList<String>["character.createdBy", "character.birthDate"]
excludeList<String>["directors"]
DashX.searchContent("email",
language = "en_US", returnType = "all",
filter = hashMapOf("identifier_eq" to "welcome"),
order = hashMapOf("created_at" to "DESC"),
limit = 10,
preview = true,
onSuccess = {
println(it)
}, onError = {
println(it)
})