whatnot
whatnot

Reputation: 11

Android app cannot handle Firebase push notifications when in background

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?

Upvotes: 1

Views: 808

Answers (2)

Mhd Sheikh
Mhd Sheikh

Reputation: 30

Maybe try changing notification: to data:

example:

   {
       "to": "/topics/dev_journal",
       "data": {
       "text":"text",
       "title":"",
       "line1":"Journal",
       "line2":"刊物"
   }

Upvotes: 0

onewrinkle
onewrinkle

Reputation: 156

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

Upvotes: 1

Related Questions