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

> Step-by-step guide to setup FCM Push notifications in flutter android app.

<Tip>
  Example integration project can be found [here](https://github.com/suprsend/suprsend-flutter-sdk/tree/main/example).
</Tip>

## Integration Steps

<Steps>
  <Step title="Create a Firebase project in the firebase console" stepNumber="1">
    To start sending notifications from FCM, you'll have to first create a firebase project. Create a firebase project and application in [firebase console](https://firebase.google.com/) with your applications package name which you can find in *`AndroidManifest.xml`*
  </Step>

  <Step title="Adding google-services.json to your project" stepNumber="2">
    You can get your Service Account JSON from Firebase Console Project Settings. Download *google-services.json* and add the file inside your *android > app* folder.

    <Frame>
      <img src="https://mintcdn.com/suprsend/jhGzZpggWCp1KSgu/images/docs/e2d76a2-Group_6.png?fit=max&auto=format&n=jhGzZpggWCp1KSgu&q=85&s=2e85e8f3794bee2bd3e1eac2ae1e0a9f" width="2212" height="1514" data-path="images/docs/e2d76a2-Group_6.png" />
    </Frame>
  </Step>

  <Step title="Adding Firebase dependencies and plugins" stepNumber="3">
    3.1. Add the below dependency inside projects *`build.gradle`* inside dependencies

    <CodeGroup>
      ```groovy Groovy (build.gradle) theme={"system"}
      dependencies {
              ...
              classpath 'com.google.gms:google-services:4.3.10' // or latest version
      }
      ```

      ```kotlin Kotlin DSL (build.gradle.kts) theme={"system"}
      plugins {
        id("com.google.gms.google-services") version "4.3.10" // or latest version
      }
      ```
    </CodeGroup>

    3.2. Add the below plugin inside the app *`build.gradle`*

    <CodeGroup>
      ```groovy Groovy (build.gradle) theme={"system"}
      apply plugin: 'com.google.gms.google-services'
      ```

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

    3.3 Add the below dependency inside apps *`build.gradle`* inside dependencies

    <CodeGroup>
      ```groovy Groovy (build.gradle) theme={"system"}
      implementation("com.google.firebase:firebase-messaging:22.0.0") // or latest version
      ```

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

  <Step title="Implementing push" stepNumber="4">
    Push feature can be implemented in two ways:

    <AccordionGroup>
      <Accordion title="Token Generation and Notification handled By SDK [Recommended]" defaultOpen={true}>
        You may use this option if all of your android push notifications are to be handled via SuprSend SDK. We recommend you use this method as it is just a single-step process to just register the service in your application manifest and everything else will be ready.

        <CodeGroup>
          ```xml AndroidManifest.xml theme={"system"}
          <!--If you are targeting to API 33 (Android 13) you will additional need to add POST_NOTIFICATIONS -->
          <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

          <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>
      </Accordion>

      <Accordion title="Token Generation and Notification handled By Your Application" defaultOpen={false}>
        Once you get a token from Firebase you can pass the token by using the below code

        <CodeGroup>
          ```javascript main.dart theme={"system"}
          suprsend.setAndroidFcmPush(fcm_token);
          ```
        </CodeGroup>

        When you get a push notification you will get a payload and it can be passed to the method provided by Suprsend Flutter SDK and the notification displaying part will be handled by SDK.

        <CodeGroup>
          ```javascript main.dart theme={"system"}
          suprsend.showNotification(notification_payload);
          ```
        </CodeGroup>

        <Info>
          ## How to identify if notification is sent by SuprSend?

          If notification payload contains key **supr\_send\_n\_pl** then simply consider this as payload sent from suprsend and pass the payload to suprsend sdk.
        </Info>
      </Accordion>
    </AccordionGroup>
  </Step>
</Steps>

### Targeting Android 13 (API-33)

In Android13 (API 33) or higher [notification permission](https://developer.android.com/develop/ui/views/notifications/notification-permission) will be disabled by default so permission needs to be asked to enable notifications if you are targeting android 13 users. You can follow [this doc](https://developer.android.com/about/versions/13/setup-sdk) to update to support Andriod 13(API 33), if not already supported. Please test the application as well as upgrading to API 33 may causes breaking changes.

<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">
    You can use [permission\_handler](https://pub.dev/packages/permission_handler) or any other package to ask notification permission to user.

    <Info>
      From v2.4.0, we have removed internal method to ask notification permission (`suprsend.askNotificationPermission`). You can use external package to ask notification permission.
    </Info>

    Once notification permission is granted, users can be able to see push notifications.
  </Step>
</Steps>

***
