Getting Started

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

Create an Input

To send data from your Android app to your mParticle workspace input, you need an API key and secret. In the mParticle dashboard, navigate to Setup > Inputs and select the Android (or Fire) platform. From here you will be able to create a key and secret. Reference the guide section for information on creating inputs.

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=""/>

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")

Verify connection

Install and open a test build of your app on a device or emulator. Your app should immediately begin uploading installation and session data and you’ll see that data arriving in the live stream almost immediately:

If you don’t see data in the live stream, check that you’ve correctly copied your API key and secret, and look in your logcat console for any errors logged by the mParticle SDK. Reference the guide section for more information on the live stream.

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.

SDK Configuration

Many other functions of the SDK are customizable via MParticleOptions, a few of which are documented below. Reference the complete API Reference for all of the configuration options.

Identify 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.


All data sent into an mParticle input must be marked as either “development” or “production”. The SDK attempts to detect the environment by based on whether the Android APK is “debuggable” according to its AndroidManifest.xml, setting it to development-mode when the API is debuggable.

In addition to uploading data as development, the SDK will also adjust some of its functionality to allow for a faster integration process:

  • In development mode, data is uploaded every 10 seconds, rather than the configurable upload interval
  • In development mode, the SDK will throw IllegalArgumentException and IllegalStateException exceptions when invalid objects are passed to its APIs, such as the IDSync and commerce APIs.
  • While in development mode, log level is configurable. See below for more information.

You can override the environment in your MParticleOptions object:

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

All development data will appear in your workspace’s live stream. In order to see production data, log into the mParticle platform, navigate to live stream, select your app, and filter on the appropriate devices based on Google Ad ID (GAID).

Data Master

Data Master allows you to define the format of any data being sent to the mParticle SDK. After creating a data plan in the mParticle UI, you simply set the data plan ID in the MParticleOptions object along with the optional data plan version and initialize the SDK as normal. When you return to the mParticle UI and visit the Live Stream section to view incoming data, you’ll find warnings for any data that has been recieved that does not conform to your data plan.

MParticleOptions options = MParticleOptions.builder(this)
   .dataplan("mobile_data_plan", 2)
var options = MParticleOptions.builder(this)
   .dataplan("mobile_data_plan", 2)

Log Level

You can configure the log level via the loglevel property of the MParticleOptions object:

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

You can also enable logging at runtime using the adb setprop command with the “mParticle” tag:

adb shell setprop log.tag.mParticle VERBOSE

Reference the Android development documentation for more information on issuing adb commands.

Event Upload Interval

To save bandwidth and device battery, mParticle does not upload each event as it is recorded. Instead, events are assembled into batches and uploaded based on specific triggers. When a trigger is fired, the SDK will:

  • Query for the current events stored in a dedicated SQLite database table
  • Assemble batches of events, enriching the batch with user, device, and other application state information
  • Store each batch in a different, dedicated SQLite table, and delete the respective events from the events table
  • Attempt to upload each batch by order of creation, including batches from previous sessions.
  • Failed uploads will be continously retried whenever the trigger next fires, and batches are individually deleted from the device only upon successful upload.

The following will trigger SDK batch creation and upload:

  • When the app is opened first time to ensure that install events are immediately available
  • When the app is sent to background
  • When a commerce event is recorded
  • When the mParticle session ends - this will be after a user navigates away from your app according to the configured session timeout
  • After the configured upload interval (see below)
  • When the manual upload API is invoked (see below)

Configured Upload Interval

You can configure the regular upload trigger:

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

Force an Event Upload

You can also force an upload trigger with the upload method:


Fire TV Support

In addition to the Google Play Store and its compatible Android devices, the same core Android SDK also supports Amazon’s Fire TV store and platform. Within a Fire TV app, the core Android SDK will attempt to query for the Amazon Advertising ID (instead of the Google Advertising ID), but otherwise the SDK functions identically.

In order to use the Android SDK within a Fire TV app, you must override the OperatingSystem during SDK initialization:

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

Was this page helpful?