# Receiving a notification

FCM

Firebase Cloud Messaging allows you to send push notifications to your users directly from your app.

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.


If you don’t have FCM integrated with your app yet you have to configure Push Notification by visiting https://firebase.google.com/docs/android/setup (opens new window).

Register token updates

You don’t have to register FCM token. SDK will do it for you.

Displaying notification

In order to show notifications to user, You must call the proper function. Note that context is required. buildNotificationOnMessageReceived(...) trigger default UI of Push Notifications and InAppMessages.

UserComSDK.instance.buildNotificationOnMessageReceived(context: context);

SDK also allows to customize UI of notifications. Just define inside onInAppMessage and onNotificationMessage what to do with incoming data. You can save them or build custom Widget.

UserComSDK.instance.buildNotificationOnMessageReceived(
  context: context,
  onInAppMessage: (message) {
    print(message.id);
  },
  onNotificationMessage: (message) {
    print(message.id);
  },
);

Remember that if You choose to build Widget to handle notifications, you also need to implement ‘notification clicked’ Event. If user interacts with notification, just trigger function sendNotificationEvent(...) and pass their id and notificationType.

UserComSDK.instance.sendNotificationEvent(...)

NOTE

SDK supports only foreground inAppMessages. Push notifications is also presented when app is working in background. When the app is closed SDK, notifications and inAppMessages will not show in system.