Cordova/Phonegap push notifications - custom template accessing payload - android

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

Related

Push notification not being sent from loopback

I have used the loopback sample application "loopback-3.x" given on:https://github.com/strongloop/loopback-example-push. The correct server key was given in config, then created an application and registered a device with that application. Then I tried sending a push notification with "notifyById" method. The console shows a succes message like:
loopback:component:push:provider:gcm Sending message to ["devicetokengiven"]: {"params":{"timeToLive":3600,"data":{"message":"sfwsed","messageFrom":"sdefsdf","badge":2}}}
loopback:component:push:provider:gcm GCM result: {"multicast_id":multicast_id,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:23423555466%24324434354"}]}
It seems to be a success, but the device doesnt get any push notification. What could be the issue? Any help would be appreciated! Thanks!
Unfortunately their last release simply doesn't work with FCM. However, in their last commit they have a change which requires an object with the attributes (messageFrom and alert) and then they convert these att to body and title. Moreover, there is a PR where someone adds another notification's attributes, but I don't think it will be merged soon.
Solutions:
Reference your module to their last commit: "loopback-component-push": "git://github.com/strongloop/loopback-component-push.git#dce16d9be30d80e258c2ac5e3dc1f74276f2b0cd"and send {messageFrom: "your title", alert: "your body"}
or
Use a simple FCM node module or even a HTTP request. Will make your life much easier.

Why is my GCM notification truncated? (Cordova PushPlugin)

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).

Ionic push notification not working on android device

I've started working with push notification, and everything works fine while using dev_push=true.
However, when I set dev_push=false, I can't get it work.
The weird thing is that it seems like my device is not recognized correctly. In the chrome console this log appear twice: $ionicPush:REGISTERED *token-value*.
I registered to the $cordovaPush:tokenReceived event, like this:
$rootScope.$on('$cordovaPush:tokenReceived', function(event, data) {
console.debug('Ionic Push: Got token ', data.token, data.platform);
});
and I saw that the event is sent twice - once with platform ios and once with android,
When I sent a one time notification from the ionic dashboard, nothing happened. Checking the message status gave this:
{"app_id":"4f0867d9","status":"Failed","ios":{"sent":0,"success":false,"failure_reason":"Push Error Code 302: See http://docs.ionic.io/docs/push-error-codes for more info."},"errors":[]}
Anyone knows what could be the problem and how to fix it?
if it is not working frome there try using POSTMAN
how to use postman
POSTMAN
//to test wether your configure correctly with ionic io open launch postman
//and then do the following things:
1-create collection give it a valid name
2-in body click on text and select Application/json
it will add header automatically
3-add another header
key as Authorization
value as Bearer followed by your api token from ionic io
4-select "raw " as the format of our json
2-in body section of your collection write
following code
{
"tokens": ["DEV_DEVICE_TOKEN"],
"profile": "PROFILE_NAME",
"notification":
{
"message": "This is my demo push!"
}
}

payload is null from server

In my app receives the push notification from GCM(for android) everything is fine am getting the notification but the payload is null. Cross checked server side script it's fine. This is the response am getting in callback method
This is the GCM response
{"type":"callback",
"source":{"pushType":"gcm", "invocationAPIs":[],
"showAppOnTrayClick":true,
singleCallback":false,
"__propertiesDefined__":true,
"bubbleParent":true,
"_events":{"callback":{},
"trayClickLaunchedApp":{},
"trayClickFocusedApp":{}},
"focusAppOnPush":false,
"enabled":false,
"showTrayNotificationsWhenFocused":false,
"apiName":"Ti.Module",
"showTrayNotification":true,"debug":false},
"payload":"","bubbles":false,
"cancelBubble":false}
Am using Titanium 3.5.1GA and tried with ti.cloudpush(3.3.7) same issues .
How can i solve it?
Since the notification does arrive it's probably not an error in the app but on the server sending the payload. Try one of the several (online) apps to test notifications on Google.

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