Reputation: 14571
I am sending messages to my app from the Console and I managed to have the app react as I want, when it is in background. So basically there is a notification shown by the SDK and when the user taps it and the app starts, I have some custom data fields to use to build a dialog message.
Since I also want the app to react when on foreground I've added the service and I've noticed that the RemoteMessage
also contains a getNotification()
method which returns RemoteMessage.Notification
which I suppose is used by the SDK to show the notification when app in background.
Is there an easy way to simply use that retrieved notification and display it, just as when the app is in background?
Upvotes: 2
Views: 2325
Reputation: 598817
There sure is. Just override FirebaseMessagingService.onMessageReceived
and get the notification body as in this example from the Firebase Cloud Messaging documentation:
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
See the Firebase Cloud Messaging documentation for receiving downstream messages on Android under "Override onMessageReceived".
Upvotes: 2