I am using the following notification payload for sending push notification to my android device using postman.
{
"to" : "device_key",
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification",
"sound": "default"
},
"data" : {
"body" : "Body of Your Notification in Data",
"title": "Title of Your Notification in Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
Notifications are received to my device and OnMessageReceived()
triggered only when the app is in the foreground. When the app is in background state OnMessageReceived
is not triggering and not triggering when tapping the notification.
I installed FirebasePushNotificationPlugin
and added notification events in App constructor like below.
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("Received");
};
CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
{
System.Diagnostics.Debug.WriteLine("Opened");
foreach (var data in p.Data)
{
System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
}
if (!string.IsNullOrEmpty(p.Identifier))
{
System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
}
};
But when receiving or tapping notification these codes are not triggering.
In one thread I found that above events are triggered when you send data message only, should not be sent notification messages if you want to use this event handler.
But if I send data messages only the notifications are not received to my device. Following is the notification payload for data messages.
{
"to" : "device_key",
"collapse_key" : "type_a",
"data" : {
"body" : "Body of Your Notification in Data",
"title": "Title of Your Notification in Title",
"key_1" : "Value for key_1",
"key_2" : "Value for key_2"
}
}
I need to open a content page in the PCL when tapping a notification. But OnNotificationReceived
or OnNotificationOpened
are not triggering. So what I am missing in this implementation?