You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
However, my first parameter is null, the second one contains the data I actually need.
My console log:
02-13 16:29:00.040 14012 14101 W System.err: org.json.JSONException: No value for message 02-13 16:29:00.040 14012 14101 W System.err: at org.json.JSONObject.get(JSONObject.java:389) 02-13 16:29:00.040 14012 14101 W System.err: at org.json.JSONObject.getString(JSONObject.java:550)
How do I manipulate Notification (message and action)?
Philip, here are some more explanations. However, you need first to be examine the payload sent to your app and what you would like to handle.
For example, payload for Android consists of a JSON object that contains either a data or notification keys in it, or both.
Utilizing the callback parameters depends on what you are sending with the payload. The message argument is usually precooked for you if there is a message key in the data payload. For full experience usually you need to leverage the second and third parameter depending on the payload and the app state (more in the documentation link from my previous reply). That is why I asked for your payload.
Example:
{
"data":{
"title":"my title",
"message":"my message", // will be populated in the first argument of the callback
... other keys
},
"notification": {
// as per the docs https://firebase.google.com/docs/cloud-messaging/concept-options
}
}
Manipulating the way the notification is shown in the notification tray is not customizable via the plugin, if this is what you would like to achieve. It can be controlled via the notification payload or with further tweaks in the native code of the plugin.
Let me know more details on the use case and surely, the structure of the payload (if convenient).
@philippsander To be honest, initially I did not get right your question.
According to your payload, your app will receive in the second argument of the callback an object with the following keys: Header, Body, and the plugin set property foreground. However, the entry in the tray will note feature any title or message because the plugin is expecting them as "title" and "message" keys in the data payload.
To change the title and message you have the following two ways. Note that you cannot change them from the app because the notification is already processed as of that moment in time (however, you should be able to create with the native APIs a new notification and place it in the tray if you need to).
From the server:
Set the title and message keys in the data payload (the plugin is designed to set them in the tray):
As you can see in the native code here the tray's notification is built there with title and message. You can use default values if you need to by modifying the plugin.
I hope this answers your question.
Some further notes:
The plugin automatically handles some keys in the data object like message, title, color, smallIcon, largeIcon and uses them to construct a notification entry in the tray. More information on these keys is available in the documentation of the Telerik Platform Notifications service documentation article.
Activity
philippsander commentedon Feb 14, 2017
can someone help me with this please?
AntonDobrev commentedon Feb 14, 2017
@philippsander At some point and depending on your payload, the
messageparameter will be empty. Please read more here - https://github.com/NativeScript/push-plugin#receive-and-handle-messages-from-fcm-on-androidIf there is further ambiguity or uncertainty let me know the payload you are sending and I will try to help you out.
Happy coding!
philippsander commentedon Feb 14, 2017
sorry... I don't understand how to use it.
PushPlugin.onMessageReceived(function callback(message, data, notification) {});this is my method. How am I supposed to change the message of the notification?
the exception I posted appears before anything I do in the body of the callback.
my data looks like this:
{\"Header\":\"PSander Test\",\"Body\":\"my body\",\"foreground\":true}AntonDobrev commentedon Feb 14, 2017
@philippsander
Philip, here are some more explanations. However, you need first to be examine the payload sent to your app and what you would like to handle.
For example, payload for Android consists of a JSON object that contains either a
dataornotificationkeys in it, or both.Utilizing the callback parameters depends on what you are sending with the payload. The
messageargument is usually precooked for you if there is amessagekey in thedatapayload. For full experience usually you need to leverage the second and third parameter depending on the payload and the app state (more in the documentation link from my previous reply). That is why I asked for your payload.Example:
Regards,
Anton
philippsander commentedon Feb 14, 2017
The firebase system is coming from someone else. I need to manipulate the notification in my app if possible. is that possible or not?
again, that's my playload in data:
{\"Header\":\"PSander Test\",\"Body\":\"my body\",\"foreground\":true}AntonDobrev commentedon Feb 14, 2017
@philippsander
Yes, you can leverage the
dataandnotificationarguments of the callback:Manipulating the way the notification is shown in the notification tray is not customizable via the plugin, if this is what you would like to achieve. It can be controlled via the
notificationpayload or with further tweaks in the native code of the plugin.Let me know more details on the use case and surely, the structure of the payload (if convenient).
EDIT:
Just reproduced it. Same comments as above.
philippsander commentedon Feb 14, 2017
I feel so stupid.... how?!
data is a string... message and notification are null
this is not working.
philippsander commentedon Feb 14, 2017
i just want to change the message of the notification from within my app... it can't be that hard.
AntonDobrev commentedon Feb 14, 2017
@philippsander To be honest, initially I did not get right your question.
According to your payload, your app will receive in the second argument of the callback an object with the following keys:
Header,Body, and the plugin set propertyforeground. However, the entry in the tray will note feature any title or message because the plugin is expecting them as "title" and "message" keys in thedatapayload.To change the title and message you have the following two ways. Note that you cannot change them from the app because the notification is already processed as of that moment in time (however, you should be able to create with the native APIs a new notification and place it in the tray if you need to).
titleandmessagekeys in thedatapayload (the plugin is designed to set them in the tray):titleandbodyof thenotification:As you can see in the native code here the tray's notification is built there with title and message. You can use default values if you need to by modifying the plugin.
I hope this answers your question.
Some further notes:
The plugin automatically handles some keys in the data object like
message,title,color,smallIcon,largeIconand uses them to construct a notification entry in the tray. More information on these keys is available in the documentation of the Telerik Platform Notifications service documentation article.philippsander commentedon Feb 14, 2017
I think it would be a handy feature to be able to modify the msgData.
beforeMessageReceived for example