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.
Related
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.
We think that Android’s push notifications by default are silent notifications and must be the developer who programmatically raise the notification on the screen. Or the push notifications aren’t silent by default?
Today we work using this JSON structure which our app receives from the GCM server.
{
"data":
{
“Type” : “2”,
“_dId” : “3718829”,
“_mId” : “9924012”,
“_msg” : “HOLA JVE”,
“collapse_key” : “9924012”
},
"to" : "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
Is this structure valid for silent notifications or there is a different one ?
Truly we are pretty lost on this topic. Following this question, anyone have a json structure of an Android push notification with message and title tags ?
Other question : When a silent notification is shown to the user ? When the user open the app or just when the user unlock the phone ?
Or the push notifications aren’t silent by default?
There are two ways that a notification is received in Android, either it's Notification Tray, or you handle it yourself in onMessageReceived() depending on which payload you use (Notification or Data).
Basing from your inquiry (silent push notification), I'm guessing you'd prefer the latter, since you'll be able to handle it yourself. As per the GCM Payload docs:
Use notifications when you want GCM to handle displaying a notification on your client app’s behalf. Use data messages when you want your app to handle the display or process the messages on your Android client app,..
So what you are currently using right now, (a data payload) should be fine. However, if you have both notification and data in your payload, you will have to consider your app's status. Referring to this FCM docs, for data payload:
App state Notification Data Both
Foreground onMessageReceived onMessageReceived onMessageReceived
Background System tray onMessageReceived Notification: system tray
Data: in extras of the intent.
..anyone have a json structure of an Android push notification with message and title tags ?
As also mentioned in the docs I linked above:
Data messages have only custom key/value pairs.
So I think it's safe for you to just use keys so long as it's not a reserved word, as mentioned in this docs:
The key should not be a reserved word ("from" or any word starting with "google" or "gcm"). Do not use any of the words defined in this table (such as collapse_key).
When a silent notification is shown to the user ? When the user open the app or just when the user unlock the phone ?
I think what I mentioned above pretty much covers this part (see the table).
On Android, differently from iOS, the app is responsible for creating and showing the push notification. So yes, you can think of them as silent by default, although you don't exactly have this concept on Android.
What I normally do is, if the notification should not be shown, add a silent field. For example:
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification" : {
"body" : "Will not show this message",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
"silent": "true"
}
}
And then you can use the silent field to show or not show the notification according to an if statement.
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
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.
I have a Json URL, which contains data about Latest Job Postings, I am successfully parsing the Json URL and able to display the top job postings in my ListView.
But my requirement is to create a push notification, so that whenever a new job is posted, the user should be able to get a notification on device.
I have followed this: http://www.vogella.com/articles/AndroidNotifications/article.html
But I don't know how to get notifications in my case.
Could anyone help me?
Issue:
Give push notification to user's device about the updated data even when application is in background mode.
Solution:
Upon successful insertion of new data in your database (which is going to give updated set of data to your JSON request) , just call the file which send GCM push notification to all your users.
Reference:
GCM docs
GCM push-notification using php server
In context of implementation presented in demo app of 2nd link,
upon successful insertion,you can call send_message.php file,but make sure that $regId and $message should be retrieved from your database
You have created ActionBar Notifications for your app, but now you need to create the ability to receive notifications from a web client, instead of going to find them yourself from the URL.
To create a push notification you would need to have a constant thread (BroadcastReceiver) on the device that is waiting for the notification from the sever.
Google 'Cloud to Device Messaging' is the simplest way to do this.
This is a good link with lots of info on how to do this :
http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/
If you require these notifications to be displayed on the device even when the application is not running (which seems to be the case from what you describe), you can use Google Cloud Messaging.
You would need a server that would poll the Json URL for updates, and send a GCM message to all the devices where your app is installed once such an update is detected.
Your app would have to register to Google Cloud Messaging and send the Registration ID received from Google to your server.
When your app receive a GCM message, you would create a notification and when the notification is tapped, you would start the activity that loads the data from the JSON URL.