Taken from Firebase documentation:
Handle notification messages in a backgrounded app
When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console). In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.
I was able to solve this by sending Custom Data with the FCM payload and then in MainActivity OnCreate() method:
var someValue = Intent.GetStringExtra("YourKey");
// if result not null then handle how you like...
In my case, I wanted to redirect the user to the view the notification is for.
Update:
There is one more way to handle this.
Override OnMessageReceived method...
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class MyFirebaseMessagingService : FirebaseMessagingService
{
public override void OnMessageReceived(RemoteMessage message)
{
SendNotification(message?.Data);
}
void SendNotification(IDictionary<string, string> data)
{
// handle your data that got passed
}
}
And instead of doing this in your example:
{
"noticiation" : {
"title" : "Test 456",
"text" : "Otra 123123"
}
}
Pass data instead:
{
"data" : {
"title" : "Test 456",
"text" : "Otra 123123"
}
}
OnMessageReceived will now be called both when your app is in the background and in the foreground.
Note that this method will mean you can't use the console in Firebase to send messages because as I'm aware, it includes "notification" in the payload.