Firebase Integration

A guide to integrate FCM push notification in android app

Suprsend Supports following type of Push notifications:

  1. FCM Push Notifications
  2. Xiaomi Push Notifications

FCM Push Notification Integration

1. Create Firebase project in firebase console

Create firebase project and application in firebase console with your applications package name which you can find in MainApplication.java or AndroidManifest.xml.

2. Adding google-services.json

Download google-services.json and add the file inside your android>app folder.

3. Adding Firebase dependencies and plugins

3.1. Add below dependency inside projects build.gradle inside dependencies

dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.10'
}

3.2. Add below plugin inside apps build.gradle

apply plugin: 'com.google.gms.google-services'

3.3. Add below dependency inside apps build.gradle inside dependencies

implementation("com.google.firebase:firebase-messaging:22.0.0")

Implementing push

Push feature can be implemented in two ways:

Option 1 - Token Generation and Notification handled By SDK
You may use this option if all of your android push notifications are to be handled via SuprSend SDK. We recommend you to 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.

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

Option 2 - Token Generation and Notification handled By Your Application:

2.1. Once you get token from Firebase you can pass the token by using below code

suprsend.user.setAndroidFcmPush(fcm_token);

2.2 When you get push notification you will get payload and it can be passed to method provided by Suprsend React Native SDK and notification displaying part will be handled by SDK.

suprsend.showNotification(notification_payload);

πŸ“˜

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 by:

if (payload?.data?.supr_send_n_pl) {
suprsend.showNotification(payload.data.supr_send_n_pl);
}