2

Does content-available have to be a first level child of the push data object for notification event handlers to be triggered by phonegap-plugin-push?

If so is there any way to set content-available: 1 as a first level child of the the push data object in notifications from firebase console?


I have created an android app with cordova CLI that uses phonegap-plugin-push and I am using Google Firebase console to send push notifications.

Push notifications work as expected when the app is in the foreground. If the app is not in the in the foreground when the push notification arrives (for example, when the app is opened by clicking the notification on the lock screen) the notification event handlers are never called.

I believe that the cause of the problem is that the content-available: 1 is inside the additionalData object.

The only place I see in firebase console to enter content-available is in the "custom data" field.

This is the push data object received when the app is in the foreground and content-available is set to 1 in Firebase console > notifications > advanced options > custom data.

data {
  title: "message title", 
  message: "test message 12", 
  additionalData: {
    content-available: "1", 
    coldstart: false, 
    collapse_key: "com.domain.appname", 
    foreground: true
    }
  }
SuprMan
  • 350
  • 4
  • 16
  • I'm not sure that your description of the resulting object structure is correct. Where are you getting the structure from your question, in particular the additionalData object is that something that the phonegap plugin is adding? – Arthur Thompson Jul 21 '16 at 16:07
  • @Arthur Thompson that is the structure of the object that the phonegap plugin passes with the JavaScript notification event. I don't know what the object that FCM sends looks like before it is processed by the plugin. I entered the key value pair `content-available: "1"` in FCM custom data section, other then that I don't know the origin of the additionalData object. – SuprMan Jul 23 '16 at 00:35
  • 1
    you cannot set content-available from the Firebase console. You have to send it from the REST API. As for the behaviour you are seeing, no callbacks when the app is in the background, this is intended behaviour. Messages sent from the Firebase console are notification messages, see more on them here: https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages – Arthur Thompson Jul 24 '16 at 15:50
  • Thanks for the clarification `content-available` is not available from the Firebase console. Regarding callbacks: I was not intending to run any callbacks in the background, I was hoping to have access to the push notification data from within the app the next time the app got focus/was opened. – SuprMan Jul 27 '16 at 20:49
  • For a notification message you would only be able to get the data payload if the user goes back to your app via tapping on the notification. If the user dismisses the notification then any data payload that was sent with the notification message will be lost. – Arthur Thompson Jul 27 '16 at 21:52
  • Hello i am Using ionic framework with FCM notifications notification working fine but my problem is how to get alert on tapping notification. i could not find that if you know plz tell me. – KAUSHAL J. SATHWARA Aug 31 '16 at 05:41
  • @KAUSHAL J. SATHWARA That is the question that I was struggling with too. Let me know if you find a solution! – SuprMan Sep 01 '16 at 18:12
  • Hello SuprMan, i done that task and i used this plugin https://github.com/fechanique/cordova-plugin-fcm. in side that past this function FCMPlugin.onNotification(.....) on Onload of app. amd must use server side "click_action":"FCM_PLUGIN_ACTIVITY", //Must be present for Android. – KAUSHAL J. SATHWARA Sep 05 '16 at 09:02

1 Answers1

0

This is the payload I am sending to Google API. This works when the app is in foreground, in backgound or when the app is closed. This works in Android and IOS:

{ 
"registration_ids":["device token"],
"content_available": true,
"notification" : {
    "force-start": "1",
    "content-available": "1",
    "no-cache": "1",
    "body":"Test" ,
    "title" : "Test",
    "sound" : "default" ,
    "icon":"default",
    "badge": 56
},
"data": {
    "force-start": "1",
    "content-available": "1",
    "no-cache": "1",
    "body":"Test" ,
    "title" : "Test",
    "sound" : "default" ,
    "icon":"default",
    "badge": 56
},
"priority":10

}

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39