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

# Android Push Setup (FCM)

## Prerequisites

* [Integration of SuprSend Flutter SDK](/docs/flutter-integration)
* Configuring [Android vendor form](/docs/firebase-fcm-androidpush) in SuprSend dashboard

<Tip>
  Example can be found in the [`example/`](https://github.com/suprsend/suprsend-flutter-sdk/tree/main/example) app.
</Tip>

## Step 1: Create a Firebase project in the firebase console

Create a Firebase project (or reuse an existing one) in the [Firebase console](https://console.firebase.google.com/) and register your Android app using its `applicationId` (the same value as `applicationId` in `android/app/build.gradle`).

## Step 2: Adding google-services.json to your project

Download the **`google-services.json`** file for your registered Android app from the Firebase console and place it in your app module:

<CodeGroup>
  ```text path theme={"system"}
  android/app/google-services.json
  ```
</CodeGroup>

## Step 3: Adding Firebase dependencies and plugins

Depending on your project, use either the **Groovy** (`*.gradle`) or **Kotlin DSL** (`*.gradle.kts`) snippets below.

<Steps>
  <Step title="Declare the Google Services Gradle plugin">
    Declare it in `settings.gradle` (top-level, `apply false`). Add it to your existing `plugins { }` block:

    <CodeGroup>
      ```groovy android/settings.gradle theme={"system"}
      plugins {
          // ...
          id "com.google.gms.google-services" version "4.3.13" apply false // or latest version
      }
      ```

      ```kotlin android/settings.gradle.kts theme={"system"}
      plugins {
          // ...
          id("com.google.gms.google-services") version "4.3.13" apply false // or latest version
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Apply the plugin in your app module">
    Add it to the existing `plugins { }` block:

    <CodeGroup>
      ```groovy android/app/build.gradle theme={"system"}
      plugins {
          // ...
          id "com.google.gms.google-services"
      }
      ```

      ```kotlin android/app/build.gradle.kts theme={"system"}
      plugins {
          // ...
          id("com.google.gms.google-services")
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Add the Firebase Messaging dependency in your app module">
    <CodeGroup>
      ```groovy android/app/build.gradle theme={"system"}
      dependencies {
          implementation "com.google.firebase:firebase-messaging:22.0.0" // or latest version
      }
      ```

      ```kotlin android/app/build.gradle.kts theme={"system"}
      dependencies {
          implementation("com.google.firebase:firebase-messaging:22.0.0") // or latest version
      }
      ```
    </CodeGroup>
  </Step>
</Steps>

## Step 4: Implementing push

### Use SuprSend Background service (Recommended)

This is the simplest way to implement push and everything is handled by the SuprSend background service, like token generating, attaching it to user, showing notification and tracking analytics. Register the SDK's messaging service inside the `<application>` tag of `android/app/src/main/AndroidManifest.xml`:

<CodeGroup>
  ```xml AndroidManifest.xml theme={"system"}
  <service
      android:name="app.suprsend.fcm.SSFirebaseMessagingService"
      android:enabled="true"
      android:exported="false">
      <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
      </intent-filter>
  </service>
  ```
</CodeGroup>

## Targeting Android 13 (API-33)

<Steps>
  <Step title="Add POST_NOTIFICATIONS permission in AndroidManifest.xml if not present already">
    <CodeGroup>
      ```xml AndroidManifest.xml theme={"system"}
      <manifest ...>
          <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
          <application ...>
              ...
          </application>
      </manifest>
      ```
    </CodeGroup>
  </Step>

  <Step title="Ask notification permission to show push notifications">
    The example uses [`permission_handler`](https://pub.dev/packages/permission_handler):

    <CodeGroup>
      ```dart Dart theme={"system"}
      import 'package:permission_handler/permission_handler.dart';

      Future<void> requestNotificationPermission() async {
        final status = await Permission.notification.status;
        // Android 13+ shows the POST_NOTIFICATIONS dialog; older versions grant by default.
        if (status.isDenied) {
          await Permission.notification.request();
        }
      }
      ```
    </CodeGroup>
  </Step>
</Steps>
