Send Mobile Push Notifications¶
You can send native push notifications to mobile client applications using the Push Notification Service.
The Push Notifications screen in the Realm UI lets you write notification drafts, send notifications to users and define notification rules.
There are four tabs in the Push Notifications screen:
In the Draft tab, you can view a list of the draft messages. For the draft messages, you can:
The Sent tab shows the messages that MongoDB Realm has already sent to registered clients. From here, you can view a list of the sent messages. For the sent messages, you can:
In the Config tab, you provide the FCM credentials (Sender ID and Legacy API key).
You can optionally specify Push Notification Rules to restrict the types of push notifications that your application sends.
Send a Push Notification¶
You can send new Push Notifications from the Push Notifications page. Click the Send New Notification button to open the Send New Notification dialog. In this dialog, you provide the notification message, label, and the relevant topic audience.
Set Up Clients to Receive Push Notifications¶
The general process of integrating Push Notifications in an Android application is as follows:
- Add a dependency for FCM.
- Create an instance of Push.
- Use the push.registerDevice() or push.registerDeviceAsync() methods to register the client for push notifications.
- Use FirebaseMessaging's subscribeToTopic() to subscribe to topics.
- Create a class that extends the abstract FirebaseMessagingService and implements the onMessageReceived() method. This class handles communication with FCM.
AndroidManifest.xmlfile for your Android project to register your
FirebaseMessagingService-derived class and a receiver for your application.
To see the latest information and detailed steps on FCM integration with Android Clients, see the official Set up a Firebase Cloud Messaging client app on Android guide.