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.
Related
We're trying to migrate from silent FCM pushes to loud ones (i.e. from "data":{} managed by the app, to those that "notification": {} causes).
With loud push, FCM client framework automatically creates a notification. Therefore:
I don't have its ID so I can modify it
I can't control its channel ID (which is important starting Oreo).
Not sure if there is a way for my server to request a specific notification sound for it (the same way they do in iOS). Actually, I can do that from onRemoteMessage() but the auto generated notification plays the default beep, which will cause a funny playing of both sounds.
How can I solve those issues?
Thanks
In case of notification payload when FCM client framework automatically creates a notification using notification payload data.
Notification payload contains a key for sound so you have to set it from server side.
For Example :
{
"to" : "yourToken",
"notification" : {
"body" : "Notification Body",
"title" : "Notification Title",
"sound" : "/res/raw/yourSoundResourceFile"
}
}
As per as firebase documentation sound is a Optional string
Supports "default" or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.
For more info follow this offical firebase link
Up until now I have been using APNS and manually connection to their services over TCP. I have packaged and delivered all push notifications in a single operation by writing all of the combined data to APNS.
Things are moving along and Android is starting to become relevant, so I looked into FCM as a common platform for push.
I cannot figure out how I am supposed to send, let's say:
"Hello (username)! Blah Blah blah blah whatever"
... to many users at one.
The FCM docs allow me to specify multiple device tokens, which is great, but they will all receive the same notification. Is there no way to customize this per device/token? Also this is a big problem when it comes to the notification badge count in iOS. If everyone receives the same notification payload, they will also receive the same badge icon count.
Am I really to believe that I am supposed to make an HTTP request for every single user to make this work properly across both iOS and Android?
{
"registration_ids" : ["token1", "token2", "token3"], <--- devices
"priority" : "normal",
"notification" : {
"body" : "Hello, Maria! Whatever blah blah", <-- Same message
"title" : "Whatever",
"badge" : "3" <--- all users receive the same? How?
}
}
I tried posting the payload as an array of above objects in a single request, but that does not work (as expected, since it's not documented).
How do we solve this?
When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.
Is there any way to handle the data payload without user tapping on the notification?
Basing from the FCM docs on Handling Messages:
App state Notification Data Both
Foreground onMessageReceived onMessageReceived onMessageReceived
Background System tray onMessageReceived Notification: system tray
Data: in extras of the intent.
It's not specifically handled ONLY by tapping on the Notification. You may handle it in the onMessageReceived(). Pretty sure the tap action also depends on how you implement it.
If you intend for it to do something else, do provide more details.
If you want to receive data payload when app is not running then you need to use a custom app-server with http protocol(in your case) which will send only data payload no notification and will send data to fcm endpoint like this
{ "data": { "some_key" : "some_value",
"some_more_key" : "some_more_value" },
"registration_ids": ["device-token","device-token2"] }
or just to send data from server to one client
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
"Nick" : "Test",
"body" : "Your message here",
"Room" : "Some Test Room"
},
}
Then using POST you can send downstream message to your device and it will work the way you want. If you want to have a basic idea of such app server please consider this : How to push notification to client when Firebase has a new entry?
I have posted basic Java Servlet code here and also a node.js code by firebase official blog.
Hope it helps.
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 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.