1

My team and I are using Firebase cloud messaging to send push notifications to our iOS and Android apps. The JSON payload that we POST to the https://fcm.googleapis.com/fcm/send endpoint contains the following fields:

{
    registration_ids: FCMTokenArray,
    data: ourCustomData,
    notification: {
        title:  '',
        body:   aString,
        sound : 'default'
    }
}

When our Android app is in the background (or closed), although the phone receives the push notifications, the app doesn't see it and therefore can't handle it. If we remove the notification key, all works ok, but then iOS complains that it needs it (basically translated by Firebase to aps)...

I don't believe that Android not forwarding the push notification to my app's handler when it's in the background is expected behavior. Does anybody have any idea about what we are missing?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
whatnot
  • 11
  • 1
  • If your app is not in the foreground and a notification message is received for your app, the system automatically shows the notification in the system tray. Your app's `onMessageReceived()` will not be invoked in this scenario. See [this section in the docs](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications) and [this question](http://stackoverflow.com/questions/37711082/how-to-handle-notification-when-app-in-background-in-firebase). – Frank van Puffelen Aug 29 '16 at 17:32

2 Answers2

1

Maybe you are missing the key "click_action" for android. Try this :

"notification":{
    "title":"Notification title",  //Any value
    "body":"Notification body",  //Any value
    "sound":"default", //If you want notification sound
    "click_action":"FCM_PLUGIN_ACTIVITY",  //Must be present for Android
    "icon":"fcm_push_icon"  //White icon Android resource
},

source: https://github.com/fechanique/cordova-plugin-fcm

onewrinkle
  • 156
  • 1
  • 6
0

Maybe try changing notification: to data:

example:

   {
       "to": "/topics/dev_journal",
       "data": {
       "text":"text",
       "title":"",
       "line1":"Journal",
       "line2":"刊物"
   }
Mhd Sheikh
  • 32
  • 3