Hi I'm trying to send notifications to an Android device.
I am using this plugin CrossGeeks/PushNotificationPlugin
I created the firebase project and extracted the parameters for use on web api that I made with .NET Core MVC 3.1
When I send the notification, the breakpoint on the event is triggered correctly
CrossPushNotification.Current.OnNotificationReceived + = (s, p) =>
However, no notification is displayed on my device.
If, on the other hand, I use the firebase console to send a notification, it appears correctly with both the inactive app and the foreground app.
For this reason, since my client application correctly receives notifications from firebase, I think the problem is server side.
This is my code:
[HttpPost, Route("Prova")] public async Task<IActionResult> SendNotication() { try { var notification = new GoogleNotification(); notification.Data = new GoogleNotification.DataPayload(); notification.Data.Title = "Title"; notification.Data.Body = "bla bla"; using (var fcm = new FcmSender("xxxxxx", "yyyyy")) { await fcm.SendAsync("hhhhhhh", notification); } return Ok("Done"); } catch (Exception ex) { return BadRequest(ex.Message); } } public class GoogleNotification { public class DataPayload { [JsonProperty("title")] public string Title { get; set; } // Add your custom properties as needed [JsonProperty("body")] public string Body { get; set; } [JsonProperty("tag")] public string Tag { get; set; } } //[JsonProperty("priority")] //public string Priority { get; set; } = "high"; [JsonProperty("data")] public DataPayload Data { get; set; } }
I have doubts about the GoogleNotification class, do you think it is correct?
I tried through the chrome console to understand the json that generates the firebase console. in fact it is very different to my code
{ "basics": {}, "productAction": { "notificationAction": { "campaignId": "1581564767326567420", "messageText": "ciao", "campaignStatus": "STATUS_ENQUEUED", "displayParameters": { "title": "Titolo", "priority": "HIGH" }, "registrationIds": [ "dcdsdsffds" ], "expiryTime": "2419200s", "lastUpdateTime": "2020-01-23T09:15:57.079Z" } } }
this sent me into confusion, I found my code on the internet and thought it was working