Skip to content
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
This repository was archived by the owner on Feb 7, 2019. It is now read-only.

JSON Error on Android in Foreground #121

Open

Description

@nraboy

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,

Activity

  1. nraboy commented on Apr 26, 2017

    @nraboy
    Author

    Seems sort of related to this #98, but not really.

  2. nraboy commented on May 2, 2017

    @nraboy
    Author

    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.

  3. EddyVerbruggen commented on May 2, 2017

    @EddyVerbruggen
    Contributor

    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.

  4. AntonDobrev commented on May 17, 2017

    @AntonDobrev
    Contributor

    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.

  5. joey0xx commented on May 31, 2017

    @joey0xx

    +1 having the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions