Why is my GCM notification truncated? (Cordova PushPlugin) - android

I'm sending a very simply GCM push notification over HTTP. On my android it displays the first 32 characters, following by 3 dots. Messages from other apps appear just fine, all wrapped nicely.
The app side is an Ionic application (Cordova) using PushPlugin as the client notification code.
example, the following code results in the message: this is not such a long message to be trun...
POST: https://android.googleapis.com/gcm/send
{
"registration_ids":["secret"],
"data": {
"message" : "this is not such a long message to be truncated"
}
}
Anyone knows this plugin and can help configuring it to display multiline notifications?

As ShibbyUK answered, use BigTextStyle:
There is a pull request for PushPlugin that does just this.
Or you could modify the plugin yourself, by making these changes:
if (extras.getString("bigview") != null) {
boolean bigview = Boolean.parseBoolean(extras.getString("bigview"));
if (bigview) {
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
}
}

You can set the style to "BigTextStyle" with setStyle when you build the notification e.g.
myBuilder.setStyle(new NotificationCompat.BigTextStyle()
.bigText("this is not such a long message to be truncated"))

The code you provided is only the server side implementation of the GCM. For the client side (e.g. Android) it seems you used the sample Google provided on its docs.
If you want to handle your message, you have to modify (or implement) the client side too. There you can choose how to display it on your devices in the Android (or iOS).

Related

Firebase Cloud Messaging Only Seeing Last Notification on Android

I am using FCM to send data push notifications to android devices via HTTP protocol. If I send several notifications, phone chimes that many times but I only only see the last notification that was sent in the notifications tray. I am NOT using the collapse_key so they should show up individually. Here is the payload:
{
"data":{
"testId":"3",
"test2Id":"2",
"title":"Test Alert Title 1",
"body":"Test Alert Body 1"
},
"to":"DEVICE_REG_ID_XXXX"
}
UPDATE:
On the device side, we're using phonegap-cordova-push plugin (https://github.com/phonegap/phonegap-plugin-push/tree/v1.9.x) in our Cordova app.
What am I doing wrong?
We were able to figure out the issue so I am posting for others who may have the same issue. The problem was with the plugin in question. Looking at the plugin code, we determined that the plugin was expecting attribute notId in the data payload to mark each notification as unique otherwise they'd get collapsed and only the latest would show up in the notification tray. So payload should like this:
{
"data":{
"testId":"3",
"test2Id":"2",
"title":"Test Alert Title 1",
"body":"Test Alert Body 1"
"notId":"45"
},
"to":"DEVICE_REG_ID_XXXX"
}
And sender needs to ensure that each FCM request has unique notId attribute.

Cordova/Phonegap push notifications - custom template accessing payload

I am building an Ionic app with VS2015 (cordova/phonegap), and using the push notification plugin. There is no problem in the actual functionality of the push notifications, I get them correctly and they are displayed to our customers.
What I am trying to do is to get the title and/or id from the payload of the notification.
The registration code is as follows:
var template = '{ "data" : {"message":"$(message)", "id": "$(id)", "title": "$(title)"}}';
// Register for
mobileServiceClient.push.gcm.registerTemplate(e.regid,"CT2", template, NOTIFICATION_TAGS_ARRAY)
When I try to access the notification (in function onGCMNotification(e)) I can only see the message and all other params in the payload are undefined (if I try accessing e.payload.id)
Can anyone help me?
Note: I am using the phonegap push plugin - not the Ionic one.
UPDATE:
I finally got it to work once, but just for the first notification - so we still have the problem.
What happened was as following:
I uninstalled the app and re-installed it.
Re-registered my custom template.
Results are that I get the notification twice:
First time - payload contains only message (not other attributes)
Second time - I get the complete payload with extra attributes.
Next time we send a notification and any other time - we get only the message in the payload without the rest of the attributes.
Cordova version 5.1.1

Worklight: save notifications in jsonStore when notification been received by device

I am using worklight for my hybrid application. I have implemented push notification which is notifying to my device. I want to pass notification to jsonstore when its been received by my device.
I am using this piece of code.
WL.Client.Push.onMessage = function (props, payload) {
//jsonStore code
//end of jsonStore code
WL.SimpleDialog.show("FMB Notification", "Provider notification data: " + JSON.stringify(props), [ {
text : 'Close',
handler : function() {
WL.SimpleDialog.show("FMB Notification", "Application notification data: " + JSON.stringify(payload), [ {
text : 'Close',
handler : function() {}
}]);
}
}]);
};
Also I am not able to receive notification when app is open.
Thanks.
If you are not able to receive notifications, why are you asking about storing them? I would imagine you will want to fix the latter in order to achieve the former... and that said - don't ask two questions in 1 question.
You do not explain what is this app that you are unable to receive push with when the app is opened. Is it iOS or Android or something else? Is it event source notifications or tag notifications? Are you certain it is properly configured? What is your MFPF version, build number? Did you follow the sample app? Is that working for you, but yours doesn't? Where is your full implementation?
Since you failed to provide any meaningful information, my suggestion to you is to take the sample application, configure it and see that you are able to receive notifications "when the app is open".
Once you get that, you can take the JSONStore sample, which demonstrates initializing a storing and saving data in it.
From there on, the road to combining the existing API calls from one sample into anothr in order to save the notification's payload value is clear.

Android GCM notifications fail from PubNub, Parse, Amazon SNS

I have been trying to send push notifications to a Phonegap app deployed on iOS and Android. iOS works fine, but Android doesn't work when I send push notifications from any of the dev consoles from PubNub, Parse and Amazon SNS.
I did verify that I can send notifications if I use the GCM API, so I am using the correct Sender ID, API key and the device token.
I don't see any errors on PubNub console. On Parse dashboard I see that the push notifications have been sent. No error on Amazon SNS. Yet, no push notifications on the device.
I am out of ideas. Thanks in advance for any helpful advice.
With help from PubNub, figured out what the issue was. The sample on PubNub has the following format
{"pn_gcm": {
"data" : {
"GCMSays" : "hi" }
}
}
But the required format was
{"pn_gcm": {
"data" : {
"message" : "hi" }
}
}
After confirming using PubNub console, I updated my JSON object in the code and it all worked like a charm.
With Parse console, I tried to create a JSON object with similar format, but it didn't work. Haven't tried Amazon SNS.
This tutorial illustrates how to configure Android GCM with PubNub: http://www.pubnub.com/docs/java/android/tutorial/google-push-notification.html
[Parse developer] Parse doesn't provide 1st party support for PhoneGap; their product just works with the JS SDK, which doesn't have native Push support. I describe what is necessary to get Parse to recognize your device for push in an arbitrary language in a previous question. You may however be receiving the push but not creating a notification.
In Android (unlike iOS, WinRT, or WinPhone), push doesn't necessarily imply "notification." The native android SDK from Parse creates this automatically for you. You'll need to create your own BroadcastReceiver and wire it to handle the intents that the Play Store app is sending for pushes. You can find these in our Android Push Tutorial. In your BroadcastReceiver, you'll want to create and register your own Notification object when receiving a push.
For Firebase Cloud Messaging, I had to use this structure to receive a tray notification:
"pn_gcm": {
"notification": {
"title": push_title,
"text": push_message
}
},

Apigee push notifications on Android not delivered when app in background (Phonegap)

I am trying to use apigee push notifications with Android phonegap app build 3.3.0, PushPlugin.
My push notifications sent when the app is in foreground are displayed correctly, but when the app is in background they are not shown.
It looks like the issue is that apigee sends a push with payload that contains "data" property (e.payload.data), instead of "message" property, and since there is no "message" property and that's why android does not display it.
Can you please advise if it is possible to change the payload format of apigee push messages or make the phonegap app to handle "data" in the payload correctly?
Thanks!
I'm not sure how flexible the phone gap plugin is regarding background processing, but yes, you may provide any payload you'd like when you create the message to push to your devices.
If you look Apigee's Creating and managing notifications document, you'll see in each example, there is a that can specified. If it is a JSON object (instead of a string), it will be delivered "as is" to the client. In other words, you could specify during notification creation that the for your notifier is something like:
{ "message" : "my message" }.
Hope that helps.

Categories

Resources