androidfirebase-cloud-messagingpubnub

Not getting Pubnub payload in bundle from Notification tray. When app is killed


I have integrated pubnub API in one of my project. I am trying to get bundle of data that i have sent in payload. I have added FCM for push notification. I am getting push notification in all cases but not getting bundle data when app is killed or in background. Already getting payload object when app is in foreground but not getting any data when app is in background or killed.

Payload 1 :

{
   "pn_gcm": {
   "notification": {
   "title": "Barack Obama",
   "body": "12",
   "channelName": "Hell 4_656"
   }
 },
"firstName": "Barack",
"lastName": "Obama",
"displayName": "Barack Obama",
"profileImageUrl": "abcURL",
"userId": "173",
"type": "sender",
"time": "1615958943297",
"message": "12"
}

PayLoad 2 :

{
pn_gcm={
  notification={
  title=BarackObama,
  body=Hello,
  image=Hell4_656
  }
  },
  firstName=Barack,
  lastName=Obama,
  displayName=BarackObama,
  time=1615958740553,
  type=sender,
  message=Hello,
  profileImageUrl=abcURL,
  userId=173
}

I am getting notification object when app is in foreground but not getting any of them when app is in background or killed.(Getting some FCM default object)

I am trying to get notification object in bundle when launch app from Notification tray

Answer Made JSON payload like this :

  {
"pn_gcm": {
  "notification": {
    "title": "Barack Obama",
    "body": "18"
  },
  "body": {
    "channelName": "Hell 5_657",
    "firstName": "Barack",
    "lastName": "Obama",
    "displayName": "Barack Obama",
    "profileImageUrl": 
    "http://3.137.127.137/quiqle/uploads/profile/1615523786_4866.jpg",
    "userId": "173",
    "type": "sender",
    "time": "1615965488916",
    "message": "18"
  }
}
}

Solution

  • You need to add data with information which you want to receive with push into pn_gcm. Information outside of pn_(gcm|apns) (including tjpse) will be delivered as regular messages

    Message can be as follows:

    using notification:

    {
       "pn_gcm":{
          "notification":{
             "title":"Chat invitation",
             "body":"John invited you to chat",
             "sound":"default"
          }
       }
    }
    

    Or using data:

    {
      "pn_gcm" : {
        "data" : {
          "room" : "Portugal vs Denmark",
          "body" : "great match!"
        }
      }
    }
    

    or both:

    {
      "pn_gcm" : {
        "notification": {
          "title":"Portugal vs Denmark",
          "body":"great match!"
        },
        "data" : {
          "room" : "Portugal vs Denmark",
          "body" : "great match!"
        }
      }
    }
    

    For an explanation on the different between data and notification, please read the official FCM docs, About FCM messages.

    See also: Why are my FCM push notifications not working?