API Reference

This page guides you to enable sending push notifications to your users.

Enable Push Notification

To enable push notifications for your application, please follow these steps:

  1. For Android 13 and above:

    • You must explicitly seek the user's consent to receive push notifications.
    • Open the AndroidManifest.xml file and add the following permission:
      <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
      
  2. For Android 12 and below:

    • If your device has Android 12 or an older version, it automatically allows notifications to be sent.
  3. To get user consent, use the subscribeToMobilePush() method as shown below:

contloPlugin.subscribeToMobilePush(<consent>) // returns true if consent was granted
  1. Depending on whether consent is granted (true) or not (false), this method either subscribes or unsubscribes your audience from Mobile Push via your Contlo Dashboard.

Set up Mobile push credentials

Open your Firebase project and follow the steps below:

  1. Go to the Project Settings and click the Service Account tab.

  1. Click the Generate new private key button to generate a JSON file with Firebase admin SDK credentials. If you have already generated one, use it for the next steps.
  2. Open the JSON file to get the credentials required for Contlo.

Push settings on Contlo Dashboard

To configure sending Push notifications from the Contlo platform, follow the steps below:

  1. Go to the Contlo Dashboard and navigate to the App Market on the left navigation bar.
  2. On the App Market screen, choose All category & search for the Mobile Push app.
  3. Open the App, go to the Android tab & set the credentials as per your Firebase JSON file, and then click Save Settings.

Integrate firebase_messaging with Contlo notification

If you are using firebase_messaging plugin in the application for push notifications, follow the steps below to make Contlo notifications work with the Firebase plugin:

Follow these steps only if you have “firebase_message” plugin in your pubspec.yaml file

  1. Open app-level build.gradle file and add this dependency:
implementation 'com.google.firebase:firebase-messaging:23.1.2'
  1. Navigate to the directory that contains the MainActivity file, create a new file NotificationService.kt, and add the following code:
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingService;
import com.contlo.contlo_plugin.ContloFlutter
import com.google.firebase.messaging.RemoteMessage

class NotificationService: FlutterFirebaseMessagingService() {
    override fun onMessageReceived(message: RemoteMessage) {
        super.onMessageReceived(message)
        ContloFlutter.processContloNotification(this, remoteMessage = message)
    }

    override fun onNewToken(token: String) {
        super.onNewToken(token)
        ContloFlutter.updateFcmToken(this, token)
    }
}
  1. Go to the AndroidManifest.xml file, and add the below service inside the tag:
  <service
            android:name=".NotificationService"
            tools:node="replace"
            android:exported="true"
            tools:ignore="Instantiatable">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

  1. In the AndroidManifest.xml file, navigate to the tag and add the tools mentioned below:
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"

Deep-linking

To enable deep-linking in the push notifications, open the AndroidManifest.xml file, add the following code inside the activity tab that you want to deep-link, and change the <data> credentials as per your application:

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="sdk"
                    android:pathPrefix="/notif"
                    android:scheme="flutterapp" />
                <data
                    android:host="sdk"
                    android:pathPrefix="/btn1"
                    android:scheme="flutterapp" />
            </intent-filter>