The Android SDK is designed to support all Android devices and tablets, including Amazon Fire TV.

Add SDK Dependencies

mParticle’s Android SDK is powered by a “core” library, which supports mParticle’s server-side integrations and audience platform. You can add the core SDK via Maven Central or jCenter. Please follow the releases page on Github to stay up to date with the latest version.

Add the following dependencies to your app’s build.gradle:

dependencies {
    implementation 'com.mparticle:android-core:5+'

    // Required for gathering Android Advertising ID (see below)
    implementation ''

    // Recommended to query the Google Play install referrer
    implementation ''

Google Play Services Ads

The Google Play Services Ads framework is necessary to collect the Android Advertising ID (also known as Google Advertising ID). AAID collection is required by all attribution and audience integrations, and many other integrations. Include the artifact, a subset of Google Play Services. The SDK will use reflection to determine if the necessary API is present at runtime.

When apps target Android 13 or above, you need to declare a Google Play services permission in the manifest file as follows:

    <uses-permission android:name=""/>

If your app does not declare this permission when targeting Android 13 or higher, the advertising ID is automatically removed and replaced with a string of zeroes.

For more information, please check out this link:

Google Play Install Referrer

The Google Play “install referrer” string contains information for how the user arrived at your listing in Google Play prior to downloading your app. Collection of this information is recommended in order for attribution, deep linking, and analytics integrations to work properly. There are two ways to collect the install referrer string via mParticle:

  • (recommended) Add the dependency to your application and the SDK will automatically gather it. This is the latest and most foolproof method
  • Collect the install referrer string and pass it to mParticle yourself, see the complete API reference for more information

Play Install Referrer Library

Add the library dependency to your app as in the example above and the Android SDK will automatically gather the install referrer string. This is the best way to collect the install referrer due to higher reliability than the intent broadcast. You can read more about the install referrer library here.

Firebase Cloud Messaging

If you’re integration push notifications via Firebase Cloud Messaging or the legacy Google Cloud Messaging, please see the Android push notification guide. If this is your first time instrumenting the mParticle SDK, we recommend continuing on and coming back to push notification instrumentation after completing the basic SDK integration below.

Initialize the SDK

You can configure the SDK with an MParticleOptions object and its respective builder class. At minimum you must supply your mParticle input key and secret via the credentials() builder API.

We recommend initializing the SDK in the onCreate() method of your app’s Application class. If you prefer, you may initialize the SDK in an Activity class - as long as the SDK is initialized prior to any other SDK API calls.

//import mParticle
import com.mparticle.MParticle;
import com.mparticle.MParticleOptions;

public class ExampleApplication extends Application {

    public void onCreate() {
        MParticleOptions options = MParticleOptions.builder(this)
                .credentials("REPLACE ME WITH KEY", "REPLACE ME WITH SECRET")
//import mParticle
import com.mparticle.MParticle
import com.mparticle.MParticleOptions

class ExampleApplication : Application() {
    override fun onCreate() {
        val options = MParticleOptions.builder(this)
            .credentials("REPLACE ME WITH KEY", "REPLACE ME WITH SECRET")

Kit Integrations

Several integrations require additional client-side add-on libraries called “kits.” Some kits embed other SDKs, others just contain a bit of additional functionality. Kits are designed to feel just like server-side integrations; you enable, disable, filter, sample, and otherwise tweak kits completely from the mParticle platform UI. Reference the kit documentation for information on kits.

Initial identification request

The SDK will automatically initialize with the most recent user identities from the most recently active user. You may override this by including an identity request via the identify API of your MParticleOptions object:

MParticleOptions.Builder options = MParticleOptions.builder(this);
var options = MParticleOptions.builder(this)

See the IDSync documentation for more information on building a complete identity request.

Was this page helpful?