Basic setup
Follow the basic setup outlined in this section to enable push notifications on an Android device using MoEngage.
- FCM Setup on MoEngage Dashboard - FCM Authentication is the method to enable sending push notifications to your app installed on Android devices. Use the methods mentioned in this article to authenticate MoEngage to access Firebase services.
- Adding metadata for push notification - Set the small icon and large icon drawable and other options to handle push notifications using the methods available in this article.
- Android Notification Runtime Permissions - When the application is running on Android 13 to show notifications to the user, applications would need to request the user for notification permission. Refer to the methods available in this article to handle permission requests.
-
Push Registration and Receiving - To use Push Notification in your Flutter application, you need to configure Firebase. Depending on your requirements, refer to one of the below methods to enable Push Registration and Receiving.
Add messaging service
You must add the messaging service to the Manifest file for MoEngage SDK to show the notifications. Refer to this document here.Callback on token registration(optional)
To get an optional callback whenever a new token is registered or the token is refreshed, refer to the method here.How to opt out of MoEngage Registration?
The MoEngage SDK attempts to register for a push token; since your application handles push, you need to opt out of SDK's token registration using the method in this article.Pass the Push Token To MoEngage SDK - After receiving the push token from FCM, use the method in this article to pass the Push Token to the MoEngage SDK to set it in the MoEngage platform.
Passing the Push payload to the MoEngage SDK - After receiving the push payload on the app, use the method in this article to send out push notifications to the device.
Notification Clicked Callback - To receive a callback whenever a push is clicked and for custom handling redirection, use the method in this article.
warning Warning
We recommend you use the Android native APIs to pass the push payload to the MoEngage SDK instead of the Flutter/Dart APIs. Flutter Engine might not get initialized if the application is in the killed state, which will lead to poor push reachability or delivery.
- Pass the Push Token To MoEngage SDK
- Pass the Push payload to the MoEngage SDK
- Callbacks and customizations
Flutter APIs for Push
You can skip this section completely if you let MoEngage handle push token registration and display or use Android Native methods to pass tokens and payload to MoEngage SDKs.
Read on if you want to use Flutter APIs of MoEngage SDK to pass tokens and payload to MoEngage SDKs.
warning |
Warning We recommend you use the Android native APIs to pass the push payload to the MoEngage SDK instead of the Flutter/Dart APIs. Flutter Engine might not get initialized if the application is in the killed state, which will lead to poor push reachability or delivery. |
Passing Push Token
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_APP_ID);
_moengagePlugin.initialise();
_moengagePlugin.passFCMPushToken();
Passing Push Payload
import 'package:moengage_flutter/moengage_flutter.dart';
final MoEngageFlutter _moengagePlugin = MoEngageFlutter(YOUR_APP_ID);
_moengagePlugin.initialise();
_moengagePlugin.passFCMPushPayload();
warning |
Warning We highly recommend you use the Android native APIs for passing the push payload to the MoEngage SDK instead of the Flutter/Dart APIs. Flutter Engine might not get initialized if the application is in the killed state, which will lead to poor push reachability or delivery. |