Push Messaging


Before continuing, please ensure that you've added the Flutter SDK to your app.

For Android

Push Notifications are messages that pop up on mobile devices. App publishers can send them at any time; even if the recipients aren’t currently engaging with the app or using their devices.
You can start sending Push Notifications to your Android users via WebEngage by configuring Firebase Cloud Messaging (FCM).

Here's how you can enable Push Messaging for your Android app via the WebEngage Flutter SDK.

Step 1: Add Firebase to Your Project by following the necessary steps in FCM Docs

Step 2: Add the below dependencies in the app-level build.gradle file.

implementation platform('com.google.firebase:firebase-bom:25.12.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging:20.2.1'
    implementation 'com.google.android.gms:play-services-ads:15.0.1'

Step 3: Add the following to your dependencies section in project/build.gradle file.

classpath 'com.google.gms:google-services:4.3.4'

Step 4: Pass Firebase tokens to WebEngage using FirebaseMessagingService.

import com.google.firebase.messaging.FirebaseMessagingService;
import com.webengage.sdk.android.WebEngage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    public void onNewToken(String s) {

Highly Recommended! Passing Firebase tokens to WebEngage from the onCreate method of your Application class ensures that changes in the user’s Firebase token are communicated to WebEngage. Here's how you can execute this.

import com.google.android.gms.tasks.Task;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.android.gms.tasks.OnCompleteListener;
import androidx.annotation.NonNull;
import com.webengage.sdk.android.WebEngage;

public class MainApplication extends FlutterApplication {
    public void onCreate() {
    .addOnCompleteListener(new OnCompleteListener<String>() {
        public void onComplete(@NonNull Task<String> task) {
          if (!task.isSuccessful()) {
            Log.w(TAG, "Fetching FCM registration token failed", task.getException());
          // Get new FCM registration token
          String token = task.getResult();

Step 5: Pass messages to WebEngage.

Create a class that extends FirebaseMessagingService and pass messages to WebEngage.
As shown below, all incoming messages from WebEngage will contain a key source with webengage as the corresponding value.

package your.application.package;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.webengage.sdk.android.WebEngage;

public class MyFirebaseMessagingService extends FirebaseMessagingService {
  public void onMessageReceived(RemoteMessage remoteMessage) {
    Map<String, String> data = remoteMessage.getData();
    if(data != null) {
      if(data.containsKey("source") && "webengage".equals(data.get("source"))) {

Step 6: Register the service to the application element of your AndroidManifest.xml file as shown below.

        <action android:name="com.google.firebase.MESSAGING_EVENT"/>

Step 7. Add your Firebase Credentials to WebEngage


And you're good to go!

For iOS

Follow our native iOS Push Messaging Guide to configure Push Messaging for your iOS Flutter app.

Please feel free to drop in a few lines at [email protected] in case you have any queries or feedback. We're always just an email away!

Did this page help you?