Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebasePushNotificationPlugin(xamarin) - events not fire when app in background(android)

I use this plugin for my Xamarin Forms app(android). Any event not fire when app is in background. Events work when the application is in the foreground. But app is background any event not fire, the app is just opening. But I need to pass the message parameters to the application. I'm not sure if this is a bug, maybe this is my mistake. I will be grateful for any help. I use this api for send message:

https://fcm.googleapis.com/fcm/send

This is my payload:

  {
 "data": {
    "id_serv" : "12",
    "id_group" : "1",
    "click_action":"Accept"
  },
  "notification" : {
     "body" : "test",
      "title" : "test"
 },
 
 "priority": "high",
  "condition": "'g1' in topics"
 }

I also subscribe to all available events - OnNotificationAction, OnNotificationOpened, OnNotificationReceived. I also try to subscribe at the android level, but this also does not work. Any help?

like image 455
FetFrumos Avatar asked Nov 07 '22 06:11

FetFrumos


1 Answers

When the app is in the background firebase use their notification system that way your code not called.

If you want that your code will be called you need to pass the data through the data object only and not use the notification object.

so your notification object need to be like that:

"data": { "id_serv" : "12", "id_group" : "1", "click_action":"Accept", "body" : "test", "title" : "test" },

"priority": "high", "condition": "'g1' in topics" }

More info here: FB Receive massages

like image 140
The Dude Avatar answered Nov 15 '22 04:11

The Dude