JSON Error on Android in Foreground
Hey,
I'm thinking this is a bug, but I'm not truly sure since this is my first time dabbling with push notifications.
On Android, while in the foreground, I get this error during the onMessageReceived event:
W/System.err( 2830): org.json.JSONException: No value for message
W/System.err( 2830): at org.json.JSONObject.get(JSONObject.java:389)
W/System.err( 2830): at org.json.JSONObject.getString(JSONObject.java:550)
My onMessageReceived looks like this:
notificationCallbackAndroid: (message, data, notification) => {
console.log("MESSAGE: " + JSON.stringify(message));
console.log("DATA: " + JSON.stringify(data));
}
While in the foreground, the message is always null, but data contains some actual data. The data parameter contains the following:
{
"foreground": true,
"custom-key1": "custom-value1",
"custom-key2": "custom-value2"
}
It contains all my custom key-value pairs, but not the actual message that was sent. For clarity, I am using FCM which I believe is the only option now, but honestly I'm not sure.
I've confirmed that in the background, I do in fact receive a notification in the tray. However, it is still useful to receive the message in the foreground.
Please let me know.
NativeScript 2.5.4 Android 5.1.1 macOS Sierra
Thanks,
Seems sort of related to this https://github.com/NativeScript/push-plugin/issues/98, but not really.
As an update, it seems the problem could be a mismatch between how the Firebase dashboard sends messages, vs what is in their API documentation.
When I send via Postman, everything is fine in the background and foreground. When I use the Firebase dashboard, I get strange results.
Just to back that comment up: I have the same experience with the Firebase plugin and the Firebase dashboard. Using a CURL script works fine though.
My 2 cents - the message parameter in the callback is populated only if there is data.message key and value, so this is pretty much expected. More information is in the [README] (https://github.com/NativeScript/push-plugin#receive-and-handle-messages-from-fcm-on-android) section for handling messages from FCM.
+1 having the same problem