Custom FCM and HMS Implementations
Custom FCM Implementation
If you have custom Firebase Cloud Messaging integration, please see usage below.
Step 1
Add the following line to your AndroidManifest.xml file inside the application tag to remove Netmera's default FCM service:
<service
android:name="com.netmera.nmfcm.NMFirebaseService"
tools:node="remove" />Step 2
Update FirebaseMessaging methods like below:
FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.getToken(vapidKey: <YOUR_KEY>).then((value) {
Netmera.onNetmeraNewToken(value);
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
if (Netmera.isNetmeraRemoteMessage(message.data)) {
Netmera.onNetmeraFirebasePushMessageReceived(message.from, message.data);
}
});
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
if (Netmera.isNetmeraRemoteMessage(message.data)) {
Netmera.onNetmeraFirebasePushMessageReceived(message.from, message.data);
}
}
Handling Background Messages in Release Mode
If you're building your Flutter project with the flutter run --release command and need to handle background messages:
Add the
@pragma('vm:entry-point')annotation to the_firebaseMessagingBackgroundHandlermethod.
This ensures that the method is correctly recognized as an entry point when building the project in release mode, which is crucial for handling background messages. By adding this annotation, you ensure that Flutter will properly recognize and invoke the background handler during release builds.
Here’s how to modify your code:
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage remoteMessage) async {
// handle message here
}Custom HMS Implementation
If you have custom Huawei Messaging integration, please see usage below.
Step 1
Add the following line to your AndroidManifest.xml file inside the application tag to remove Netmera's default HMS service:
<service
android:name="com.netmera.nmhms.NMHuaweiService"
tools:node="remove" />Step 2
Update HuaweiPushKit methods like below:
Push.getTokenStream.listen((String token) {
Netmera.onNetmeraNewToken(token);
});
Push.onMessageReceivedStream.listen((RemoteMessage remoteMessage) {
Map<String, String> map = remoteMessage.dataOfMap ?? new Map();
if (Netmera.isNetmeraRemoteMessage(map)) {
Netmera.onNetmeraHuaweiPushMessageReceived(remoteMessage.from, map);
}
});Last updated
Was this helpful?