I'm using C2DM to send notification for my android App and it is working fine. But i am able to get only one notification at a time. so that while receiving the notification, it replaces previously received notification.
So how to receive multiple C2DM notification, like receiving normal SMS?
Give the messages different collapse_keys. Here's an excerpt from the official docs:
An arbitrary string that is used to collapse a group of like messages
when the device is offline, so that only the last message gets sent to
the client. This is intended to avoid sending too many messages to the
phone when it comes back online. Note that since there is no guarantee
of the order in which messages get sent, the "last" message may not
actually be the last message sent by the application server. Required.
On a side note; you are not supposed to use the push messages too frequently:
Are you sending C2DM messages too frequently? If you need to
communicate with your application frequently over a short period of
time, C2DM is probably not the best solution. Instead, consider
implemeting XMPP or your own protocol to exchange messages, and use
C2DM only to send the initial notification.
Related
I am using Firebase Cloud Messaging to send data messages to my Android app. It is possible that the devices goes offline and that there are multiple data messages queued on the server to be send to a specific device.
When a message is received I have to execute some specific code based on the data inside the message.
Is there some way to be sure that when you receive a message in onMessageReceived() that there are no other messages in the queue to be delivered to my device?
I am asking this because when receiving multiple messages, the data in all messages need to be combined before starting my processing.
Thanks!
I think using FCM alone isn't the best for this use case. In general, FCM's expected behavior is to send the message(s) as soon as feasible.
One thing to remind also is that FCM is a push notification service. So a use-case where you need data to be synced is not a good match.
The way I can think of that you can use FCM here is to simply send a push notification, informing the user that there needs data to be synced. Upon tapping the notification, you can use a DownloadManager (not really sure what data you need synced, but for downloads, it usually this) to download the data you need, then process the data.
I have developed an app using GCM for push notification.My app using for stacking purpose so I have to receive notification like in First in First out order.But now am not getting notification from GCM in order.How to manage to receive notification in order and is possible to manage GCM server from our end.
No it's not possible in GCM server. But another way is you can Hack this Notification in your Server triggered by GCM and Run a cron at particular order.
no you cannot get the notification in first in first out order .they are randomly generated by the server.you can do this in your server connected with GCM and put them in serial order
gcm document already mention this
http://developer.android.com/google/gcm/adv.html
Note that the order of delivery is not guaranteed.
GCM order of message is not guaranteed. For this you can achieve another way.
Ask to server guys to create API(Webserver) for message, The message is same as they were earlier sending through the GCM.
After that you have to create Calender scheduler (Like Every 5 min) and then call this web-service and show notification.
I am planning to implement Android push notification serivce for an app that might require receiveing even two messages per device per second. I would like to know if GCM Push messaging is the way to go or should I stick to SyncAdapter or some other technology? Single device will receive up to few thousand notifications per day. Message size will be very small to 4kb limit is fine.
If it is critical that all of the messages reach the device and none are lost, GCM alone is not the right choice, since in case GCM server would temporarily lose connection with a device, there's a limit to the number of messages that would be stored for later delivery for that device in the GCM server.
Therefore, if you have to update your app that frequently, you should probably keep an open connection between your server and your app, and load data from the server periodically.
Though the GCM server limits the number of messages that will be stored for later delivery in the case of a device disconnect, you can always create a collapse_key.
According to GCM documentation, if there is already a message with the same collapse key (and registration ID) stored and waiting for delivery, the old message will be discarded and the new message will take its place (that is, the old message will be collapsed by the new one).
Essentially, if you only need the most recent push notifications rather than all prior sent, GCM is acceptable for sending push notifications with high frequency.
You can read more about this in the GCM Advanced Topics.
I'm using C2DM notification service. When I send 2 consecutive notification, I can see only the second one. My question is can notifications form same service are replaced?
I don't really understand your question, but if two messages sent with the same collapse_key before the first one is handled by the device, the server automatically removes the first one. So if you need several messages to arrive, change the value of the key.
You can read a little bit more about this here: https://developers.google.com/android/c2dm/?hl=sv-SE#push
This may be due to the fact that C2DM messages are not guaranteed to be delivered (kind of like UDP instead of TCP). Some services, such as Urban Airship claim to address this problem/feature.
I have successfully implemented the android push notification using google c2dm.
the problem is,when i push the message from the server i am getting success full deveice id. but the device some time receive push message,some time did not receive.(wifi is fully active)
i want the app to receive all the push message with out any push message lose,becoz each notification is important.
Is there any special parameter need to set or hw i would i confirm that device successfully received the message.
"C2DM makes no guarantees about delivery or the order of messages. So, for example, while you might use this feature to tell an instant messaging application that the user has new messages, you probably would not use it to pass the actual messages."
But you can try to play with 2 parameters:
collapse_key
An arbitrary string that is used to collapse a group of like messages when the device is offline, so that only the last message gets sent to the client. This is intended to avoid sending too many messages to the phone when it comes back online. Note that since there is no guarantee of the order in which messages get sent, the "last" message may not actually be the last message sent by the application server. Required.
delay_while_idle
If included, indicates that the message should not be sent immediately if the device is idle. The server will wait for the device to become active, and then only the last message for each collapse_key value will be sent. Optional.