> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mixpanel/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Android SDK

> Track events from Android apps with the Mixpanel Android SDK

## Installation

<Steps>
  <Step title="Add dependency">
    Add to your `app/build.gradle`:

    ```gradle theme={null}
    dependencies {
      implementation "com.mixpanel.android:mixpanel-android:7.+"
    }
    ```
  </Step>

  <Step title="Sync Gradle">
    Click "Sync Project with Gradle Files" in Android Studio.
  </Step>

  <Step title="Add permissions">
    Add to your `AndroidManifest.xml`:

    ```xml theme={null}
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    ```
  </Step>

  <Step title="Initialize Mixpanel">
    ```java theme={null}
    import com.mixpanel.android.mpmetrics.MixpanelAPI;

    public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MixpanelAPI mixpanel = MixpanelAPI.getInstance(
          this,
          "YOUR_PROJECT_TOKEN",
          false // trackAutomaticEvents
        );
      }
    }
    ```
  </Step>
</Steps>

## Track Events

```java theme={null}
MixpanelAPI mixpanel = MixpanelAPI.getInstance(context, "YOUR_PROJECT_TOKEN", true);

JSONObject props = new JSONObject();
props.put("Gender", "Female");
props.put("Plan", "Premium");

mixpanel.track("Purchase", props);
```

### Timing Events

```java theme={null}
mixpanel.timeEvent("Image Upload");

// 20 seconds later
if (imageUpload()) {
  mixpanel.track("Image Upload");
}
```

### Flush Events

```java theme={null}
// Flush immediately
mixpanel.flush();

// Set batch size
mixpanel.setFlushBatchSize(100);
```

## Identify Users

```java theme={null}
// User signs in
mixpanel.track("sign in");
mixpanel.identify("12345");
```

### Reset on Logout

```java theme={null}
mixpanel.track("log out");
mixpanel.reset();
```

## User Profiles

```java theme={null}
mixpanel.identify("12345", true);

// Set single property
mixpanel.getPeople().set("plan", "Premium");

// Set multiple properties
JSONObject props = new JSONObject();
props.put("name", "John");
props.put("email", "john@example.com");
mixpanel.getPeople().set(props);
```

<Tabs>
  <Tab title="setOnce()">
    ```java theme={null}
    mixpanel.getPeople().setOnce("name", "John");
    mixpanel.getPeople().setOnce("location", "US");
    ```
  </Tab>

  <Tab title="increment()">
    ```java theme={null}
    mixpanel.getPeople().increment("age", 1);
    mixpanel.getPeople().increment("login_count", 1);
    ```
  </Tab>

  <Tab title="append()">
    ```java theme={null}
    mixpanel.getPeople().append("roles", "admin");
    ```
  </Tab>

  <Tab title="union()">
    ```java theme={null}
    mixpanel.getPeople().union("skills", new JSONArray().put("Java").put("Kotlin"));
    ```
  </Tab>
</Tabs>

## Super Properties

```java theme={null}
JSONObject props = new JSONObject();
props.put("name", "John");
mixpanel.registerSuperProperties(props);

// Register without overwriting
JSONObject moreProps = new JSONObject();
moreProps.put("name", "Jane"); // Ignored
moreProps.put("city", "San Francisco"); // Set
mixpanel.registerSuperPropertiesOnce(moreProps);
```

## Group Analytics

```java theme={null}
// Assign to group
mixpanel.setGroup("company", "Acme Inc");

// Track event (group included automatically)
mixpanel.track("feature_used");

// Set group properties
mixpanel.getGroup("company", "Acme Inc").set("industry", "Technology");
```

## Privacy Controls

### Opt Out

```java theme={null}
mixpanel.optOutTracking();

// Initialize with opt-out
boolean optOutTrackingDefault = true;
MixpanelAPI mixpanel = MixpanelAPI.getInstance(
  context,
  "YOUR_PROJECT_TOKEN",
  optOutTrackingDefault,
  false
);
```

### EU Data Residency

Add to `AndroidManifest.xml`:

```xml theme={null}
<application>
  <meta-data
    android:name="com.mixpanel.android.MPConfig.EventsEndpoint"
    android:value="https://api-eu.mixpanel.com/track?ip=1" />
  <meta-data
    android:name="com.mixpanel.android.MPConfig.PeopleEndpoint"
    android:value="https://api-eu.mixpanel.com/engage?ip=1" />
  <meta-data
    android:name="com.mixpanel.android.MPConfig.GroupsEndpoint"
    android:value="https://api-eu.mixpanel.com/groups" />
</application>
```

### Disable Geolocation

```xml theme={null}
<meta-data
  android:name="com.mixpanel.android.MPConfig.UseIpAddressForGeolocation"
  android:value="false" />
```

## Debug Mode

```xml theme={null}
<application>
  <meta-data
    android:name="com.mixpanel.android.MPConfig.EnableDebugLogging"
    android:value="true" />
</application>
```

## Platform Considerations

* Events flush every 60 seconds or on app background
* Batch size: 50 events by default
* Requires Android API level 16+
* Supports App Links tracking
* Session Replay requires separate SDK

## Resources

* [Full API Reference](http://mixpanel.github.io/mixpanel-android/index.html)
* [GitHub Repository](https://github.com/mixpanel/mixpanel-android)
* [Example App](https://github.com/mixpanel/sample-android-mixpanel-integration)
