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

# SDK Quickstart - Android

> Start sending your first notification in 10 minutes.

## Before Getting Started

### Overview

Clix leverages Firebase Cloud Messaging (FCM) to deliver notifications efficiently. The goal is to ensure a smooth integration process and reliable delivery of push notifications to your app users.

### Environment

* Android API level 26 (Android 8.0) or later
* Firebase account

<Note>
  [**Make sure you've completed the Firebase setup.**](/firebase-setting)

  If the setup is complete, the following items should be in place:

  * Make sure google-services.json is in your project directory.
  * Upload the Service Account Key file to the Clix console.
</Note>

## Setup Clix - Using CLI (Recommended)

Clix CLI is an AI-powered assistant for quick and easy SDK setup.

Use the install and doctor commands to automatically configure the required code and settings.

#### Install Clix CLI

<CodeGroup>
  ```bash npm theme={null}
  npm install -g @clix-so/clix-cli
  ```

  ```bash shell theme={null}
  curl -fsSL https://cli.clix.so/install.sh | bash
  ```

  ```bash homebrew theme={null}
  brew tap clix-so/clix-cli && brew install clix
  ```
</CodeGroup>

#### Run Install Command

The install command checks for required files and configurations, then guides you through the installation process with interactive prompts.

```bash theme={null}
clix install
```

### Doctor Command

The clix doctor command verifies that your Clix SDK setup is correct and provides guidance on fixing any issues.

```bash theme={null}
clix doctor
```

## Setup Clix - Manual Installation

<Info>
  Integrate Firebase and Clix to manage and send notifications effectively from
  Clix console.
</Info>

<img src="https://maven-badges.sml.io/sonatype-central/so.clix/clix-android-sdk/badge.svg" alt="Sonatype Central release (latest by date)" style={{ width: "20%" }} />

<AccordionGroup>
  <Accordion title="1. Installation" defaultOpen="true">
    <Note>
      Clix Android SDK supports installation only via **Gradle (Kotlin DSL).**
    </Note>

    #### (Option 1) Using Version Catalog (Recommended)

    If you're using the Gradle Version Catalog (`libs.versions.toml`), follow the steps below for more consistent dependency management.

    1. Add the version and library alias to `gradle/libs.versions.toml` (create the file if it doesn't exist):

    ```toml theme={null}
    [versions]
    clix-android-sdk = "1.X.X" # Replace with the latest SDK version

    [libraries]
    clix-android-sdk = { module = "so.clix:clix-android-sdk", version.ref = "clix-android-sdk" }
    ```

    2. (Optional) If you use a custom catalog file name, adjust the accessor accordingly. If you're using the default (`libs`), no extra configuration is required.

    3. In your app module's `build.gradle.kts`:

    ```kotlin theme={null}
    dependencies {
      // TOML alias: clix-android-sdk -> Gradle accessor: libs.clix.android.sdk
      implementation(libs.clix.android.sdk)
    }
    ```

    > When Gradle generates accessors, hyphens (-) in the alias are converted to dots (.) resulting in `libs.clix.android.sdk`.

    ***

    #### (Option 2) Without Version Catalog (Direct Declaration)

    Add the following to your project's `settings.gradle.kts` or `build.gradle.kts`:

    ```kotlin theme={null}
    repositories {
      mavenCentral()
    }
    ```

    Add the dependency to your app's `build.gradle.kts`:

    ```kotlin theme={null}
    dependencies {
      implementation("so.clix:clix-android-sdk:1.X.X") // Replace with the latest SDK version
    }
    ```

    Lastly, add the plugin to your app's `build.gradle.kts`:

    ```kotlin theme={null}
    plugins {
      id("com.google.gms.google-services") version "4.X.X" // Replace with the latest version
    }
    ```
  </Accordion>

  <Accordion title="2. Initialize Clix with Config" defaultOpen="true">
    Add this code to your `Application` class. The endpoint and logLevel parameters are optional. If your project doesn't have an `Application` class, refer to [this link](https://pushalert.co/documentation/android-app-push-notification/create-application-class-android-app) to add one.

    ```kotlin Application.kt lines highlight={9-15} theme={null}
    import so.clix.core.Clix
    import so.clix.core.ClixConfig
    import so.clix.utils.logging.ClixLogLevel

    class MyApplication : Application() {
        override fun onCreate() {
            super.onCreate()

    		Clix.initialize(
                this,
                ClixConfig(
                    projectId = "YOUR_PROJECT_ID",
                    apiKey = "YOUR_API_KEY",
                ),
            )
        }
    }
    ```
  </Accordion>

  <Accordion title="3. Add Permission Code" defaultOpen="true">
    Add this code to your `Application` class, right after the `Clix.initialize` code.

    ```kotlin Application.kt lines highlight={18-23} theme={null}
    import so.clix.core.Clix
    import so.clix.core.ClixConfig
    import so.clix.utils.logging.ClixLogLevel

    class MyApplication : Application() {
        override fun onCreate() {
            super.onCreate()

    		Clix.initialize(
          this,
          ClixConfig(
              projectId = "YOUR_PROJECT_ID",
              apiKey = "YOUR_API_KEY",
          ),
        )

        // STEP 2: Configure notification handling after initialization
        // Note: autoRequestPermission defaults to false
        Clix.Notification.configure(
          autoRequestPermission = false,  // Set to true to automatically request permission
          autoHandleLandingURL = false     // Set to true to automatically open landing URLs
        )
      }
    }
    ```

    By default, `autoRequestPermission` is set to `false`, which means the app will not automatically request push notification permission.

    There are two options to implement the push notification permission flow:

    #### (Option 1) Automatically request permission right after app launch

    Simply set `autoRequestPermission` to `true`.

    ```kotlin Application.kt highlight={4} theme={null}
    // STEP 2: Configure notification handling after initialization
    // Note: autoRequestPermission defaults to false
    Clix.Notification.configure(
      autoRequestPermission = true,  // Set to true to automatically request permission
      autoHandleLandingURL = false     // Set to true to automatically open landing URLs
    )
    ```

    #### (Option 2) Manually control when to show the permission prompt

    If you want to request permission at a specific point in your app, leave it as `false` and call the following code when you're ready to request permission.

    ```kotlin MainActivity.kt lines highlight={8-12} theme={null}
    import androidx.lifecycle.lifecycleScope
    import kotlinx.coroutines.launch

    class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Call this code wherever you want to request permission from the user
        lifecycleScope.launch {
          val granted = Clix.Notification.requestPermission()
          Clix.Notification.setPermissionGranted(granted)
        }
      }
    }
    ```
  </Accordion>

  <Accordion title="4. Build & Run" defaultOpen="true">
    Run your project to verify that the setup works correctly. Go to Clix console > Test Console, find the registered device, send a test push notification, and confirm that the message is received on the device. Also, make sure the push events are being tracked in real time.

    <Note>
      If you're using an emulator, make sure it is started with **Cold Boot** to properly test push notification delivery. For more details, see [this guide](https://docs.clix.so/trouble-shooting/not-getting-push-notification#emulator-not-started-with-cold-boot).
    </Note>
  </Accordion>
</AccordionGroup>

<CardGroup cols={1}>
  <Card title="Setup Firebase" icon="fire" href="https://docs.clix.so/firebase-setting">
    You need to set up Firebase before you start integrating it into your
    project.
  </Card>

  <Card title="Clix Sample Project - Android" icon="github" iconType="regular" href="https://github.com/clix-so/clix-android-sdk/tree/main/samples/basic-app">
    If you’d like to see a working example, check out our sample project.
  </Card>
</CardGroup>
