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

# Android

> Install and initialize the Notifly Android SDK and integrate push notifications and in-app popups.

The Notifly Android SDK connects your Android app to Notifly.\
The SDK supports the following features:

* Register devices with Notifly to receive push notifications and display in-app popups.
  (In-app popups appear only while the app is in the foreground.)
* Send event and user data to Notifly for campaign targeting and analysis.
* Log user behavior as events and measure campaign performance.

## Prerequisites

1. **Connect your Firebase project.**\
   The Notifly Android SDK uses [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) to send push notifications.

> [Connect Firebase](https://docs.notifly.tech/en/developer-guide/firebase-integration.md)

2. **Android 11 (API level 30) or later for in-app popups.**\
   In-app popup campaigns are supported only on Android 11 or later.

***

## 1. Install the SDK

The Notifly Android SDK is distributed through [JitPack](https://jitpack.io/).

### Configure Gradle

> [tab] Gradle 7.0 or later
>
> ```gradle title="settings.gradle" highlight={3} theme={null}
> dependencyResolutionManagement {
>     repositories {
>         maven { url 'https://jitpack.io' }
>     }
> }
> ```

> [tab] Earlier than Gradle 7.0
>
> ```gradle title="build.gradle (root)" highlight={4} theme={null}
> allprojects {
>     repositories {
>         ...
>         maven { url 'https://jitpack.io' }
>     }
> }
> ```

### Add the SDK dependency

```gradle title="build.gradle (Module: app)" theme={null}
dependencies {
    implementation 'com.github.team-michael:notifly-android-sdk:1.12.0'
}
```

> [!NOTE]
>
> The SDK receives frequent feature and security updates. Use the [latest version on JitPack](https://jitpack.io/#team-michael/notifly-android-sdk).

### Initialize the SDK

Initialize the SDK in your `Application` class. If you initialize it in a specific Activity, initialization may not apply to other Activities.

> [!NOTE]
>
> If your app **does not have an Application class**,\
> create one and register it with the `android:name` attribute in `AndroidManifest.xml`.

```xml title="AndroidManifest.xml" highlight={4} theme={null}
<!-- Register the Application class. -->
<application
    ...
    android:name=".MainApplication"
    ... >
</application>
```

> [tab] Kotlin
>
> Add the following code to `onCreate` in your app's Application class.
>
> ```kotlin title="MainApplication.kt" highlight={6-11} theme={null}
> import tech.notifly.Notifly
>
> class MainApplication : Application() {
>     override fun onCreate() {
>         super.onCreate()
>         Notifly.initialize(
>             applicationContext,
>             NOTIFLY_PROJECT_ID,
>             BuildConfig.NOTIFLY_USERNAME,
>             // password is a legacy compatibility placeholder. Do not pass a real password or API Secret Key.
>             BuildConfig.NOTIFLY_USERNAME
>         )
>     }
> }
> ```

> [tab] Java
>
> Add the following code to `onCreate` in your app's Application class.
>
> ```java title="MainApplication.java" highlight={8-13} theme={null}
> import tech.notifly.Notifly;
>
> public class MainApplication extends Application {
>     @Override
>     public void onCreate() {
>         super.onCreate();
>         ...
>         Notifly.initialize(
>             this,
>             NOTIFLY_PROJECT_ID,
>             BuildConfig.NOTIFLY_USERNAME,
>             // password is a legacy compatibility placeholder. Do not pass a real password or API Secret Key.
>             BuildConfig.NOTIFLY_USERNAME
>         );
>         ...
>     }
> }
> ```

> [!NOTE]
>
> Find `NOTIFLY_PROJECT_ID` and `USERNAME` on the settings page. `PASSWORD` is a placeholder for backward compatibility. Pass the same nonempty value as `USERNAME`. Do not pass a real password or API Secret Key.

***

## 2. Register user information

Notifly uses user identifiers (`userId`) and user properties (`params`) to personalize marketing campaigns.\
Registered user information supports **segmentation and targeting for channels such as push notifications, email, and Kakao AlimTalk**.

> [!NOTE]
>
> Complete SDK initialization with `Notifly.initialize()` before calling the user methods.

### Set the user ID (`Notifly.setUserId()`)

```kotlin theme={null}
Notifly.setUserId(context: Context, userId: String?)
```

Map `userId` to the identifier of the signed-in user in your app.\
Notifly uses this value to track user events and personalize campaigns.

**context** `Context` *required*

Android context object.

**userId** `String` *required*

The signed-in user's ID. Pass `null` on sign-out to clear the association.

#### Clear the user ID

On sign-out, call `setUserId(null)` to clear the association between the current device and the user.
To retain the same user data, manage it separately on your server or in your app.

> [tab] Kotlin
>
> ```kotlin title="setUserId" theme={null}
> import tech.notifly.Notifly
>
> // On sign-in.
> Notifly.setUserId(context, "user_12345")
>
> // On sign-out.
> Notifly.setUserId(context, null)
> ```

> [tab] Java
>
> ```java title="setUserId" theme={null}
> import tech.notifly.Notifly;
>
> Context context = getApplicationContext();
>
> // On sign-in.
> Notifly.setUserId(context, "user_12345");
>
> // On sign-out.
> Notifly.setUserId(context, null);
> ```

### Set user properties (`Notifly.setUserProperties()`)

`setUserProperties` registers properties for the user.\
These properties support **segment targeting**, **message personalization**, and **delivery channel selection**.

> [!NOTE]
>
> **Before you send sensitive user properties**
>
> Before you send a custom user property that needs protection, such as a name or address, register it with the exact key you plan to send and enable encryption under **User Management > User List > Property management** in the console.
>
> See [Manage user properties](https://docs.notifly.tech/en/user-guide/users/properties.md) for setup instructions and limitations.

```kotlin theme={null}
Notifly.setUserProperties(context: Context, params: Map<String, Any?>)
```

**context** `Context` *required*

Android context object.

**params** `Map\<String, Any?\>` *required*

Key-value pairs of user properties. Supports predefined keys such as `$email`, `$phone_number`, and `$line_user_id`.

> [!NOTE]
>
> * `$email`: Email address for email campaigns.
> * `$phone_number`: Phone number for SMS and Kakao campaigns.
> * `$line_user_id`: LINE user ID for LINE message campaigns.
> * Custom fields: Define your own fields, such as `"plan"`, `"tier"`, and `"country"`.

> [tab] Kotlin
>
> ```kotlin title="setUserProperties" theme={null}
> import tech.notifly.Notifly
>
> // Register an email address, phone number, and plan.
> Notifly.setUserProperties(
>     context,
>     mapOf(
>         "\$email" to "user@example.com",
>         "\$phone_number" to "01012345678",
>         "plan" to "premium",
>         "language" to "ko"
>     )
> )
> ```

> [tab] Java
>
> ```java title="setUserProperties" theme={null}
> import tech.notifly.Notifly;
>
> Context context = getActivity();
>
> HashMap<String, Object> userProperties = new HashMap<>();
> userProperties.put("$email", "user@example.com");        // Email campaigns.
> userProperties.put("$phone_number", "01012345678");      // SMS / KakaoTalk.
> userProperties.put("membership_tier", "gold");           // Custom segmentation field
>
> Notifly.setUserProperties(context, userProperties);
> ```

***

## 3. Log events (`Notifly.trackEvent()`)

Record user behavior to use in **campaign triggers**, **segment conditions**, and **performance analysis**.\
For example, collect button clicks, page visits, and completed purchases as events.

```kotlin theme={null}
Notifly.trackEvent(
    context: Context,
    eventName: String,
    eventParams: Map<String, Any?> = emptyMap(),
    segmentationEventParamKeys: List<String>? = null,
)
```

**context** `Context` *required*

Android context object.

**eventName** `String` *required*

Event name, such as `"click_button"` or `"purchase_completed"`.

**eventParams** `Map\<String, Any?\>`

Additional event parameters, such as `"plan": "premium"` or `"duration": 120`.

**segmentationEventParamKeys** `List\<String\>`

List of event parameter keys to use for segmentation. Supports at most one key.

> [!NOTE]
>
> `segmentationEventParamKeys` currently supports **at most one key**.
>
> * For example, `listOf("plan")` makes the `"plan"` event parameter available for segmentation.

> [tab] Kotlin with Jetpack Compose
>
> ```kotlin title="Notifly.trackEvent" highlight={5-13} theme={null}
> import tech.notifly.Notifly
> ...
> Button(
>     onClick = {
>         Notifly.trackEvent(
>             context,
>             "click_button_1",
>             mapOf(
>                 "signup_method" to "kakao",
>                 "purchased" to "true",
>                 "duration" to 45,
>             ),
>             listOf("signup_method") // Use signup_method as the segmentation key.
>         )
>     },
>     modifier = Modifier.padding(top = 16.dp)
> ) {
>     Text(text = "click_button_1")
> }
> ...
> ```

> [tab] Kotlin with XML
>
> ```kotlin title="Notifly.trackEvent" highlight={3-34} theme={null}
> import tech.notifly.Notifly
> ...
> val button = findViewById<Button>(R.id.button)
>
> // With lambda representation
> button.setOnClickListener {
>     Notifly.trackEvent(
>         context,
>         "click_button_1",
>         mapOf(
>             "signup_method" to "kakao",
>             "purchased" to "true",
>             "duration" to 45,
>         ),
>         listOf("signup_method") // Use signup_method as the segmentation key.
>     )
> }
>
> // Without lambda representation
> button.setOnClickListener(object : View.OnClickListener {
>     override fun onClick(v: View) {
>         Notifly.trackEvent(
>             context,
>             "click_button_1",
>             mapOf(
>                 "signup_method" to "kakao",
>                 "purchased" to "true",
>                 "duration" to 45,
>             ),
>             listOf("signup_method") // Use signup_method as the segmentation key.
>         )
>     }
> })
> ...
> ```

> [tab] Java
>
> ```java title="Notifly.trackEvent" highlight={8-20} theme={null}
> import tech.notifly.Notifly;
>
> HashMap<String, Object> map = new HashMap<>();
> map.put("signup_method", "kakao");
> map.put("purchased", true);
> map.put("duration", 45);
>
> // Create segmentation key list
> List<String> segmentationEventParamKeys = Arrays.asList("signup_method");
>
> Button button = findViewById(R.id.button);
>
> // With lambda representation
> button.setOnClickListener(v -> {
>     Notifly.trackEvent(context, "click_button_1", map, segmentationEventParamKeys);
> });
>
> // Without lambda representation
> button.setOnClickListener(new View.OnClickListener() {
>     public void onClick(View v) {
>         Notifly.trackEvent(context, "click_button_1", map, segmentationEventParamKeys);
>     }
> });
> ```

***

## 4. Get the internal user ID

`getNotiflyUserId()` returns the unique user ID that Notifly manages internally.\
This ID is **separate from the user ID set with `setUserId()`**. Most integrations do not need it.\
Use it when an external CRM or third-party integration requires Notifly's internal user ID.

```kotlin theme={null}
Notifly.getNotiflyUserId(context)
```

***

## 5. Test the integration

After you install the SDK, follow [Test your integration](https://docs.notifly.tech/en/integration-test.md) to verify event collection and push notification delivery.

***

## 6. Advanced integration

> [card] [Push notification icons](https://docs.notifly.tech/en/advanced/push-notification-icon.md)

> [card] [Request push notification permission](https://docs.notifly.tech/en/advanced/push-notification-consent.md)

> [card] [Push notification click events](https://docs.notifly.tech/en/advanced/push-notification-click-events.md)

> [card] [Push notification interceptor](https://docs.notifly.tech/en/advanced/push-notification-interceptor.md)

> [card] [In-app popup event listener](https://docs.notifly.tech/en/advanced/inapp-popup-event-listener.md)

> [card] [WebView](https://docs.notifly.tech/en/advanced/webview.md)

***

## FAQ

> [accordion] Can I use Notifly with an existing Firebase Cloud Messaging integration?
>
> The Notifly Android SDK can work alongside Firebase Cloud Messaging that your app already uses.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.