How can I send Heartbeat to GCM Server - android

How can I send heartbeat to the GCM server . So that we could keep the connection alive.
I used the below code to send heartbeat to the GCM server.
mContext.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
mContext.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
But it again delayed the message.
After a long idle state I sent a notification to my app and gmail app.
The Gmail app receives the notification within time and my app not.
How it is happened. AFAIK The GCM uses port 5228 to receive messages. Then Why gmail received the message on time and my app received message after a long time.
What should I do to receive the messages on time.

Couple solutions that come in to mind:
Did you try to set delay_while_idle flag to false?
You can force android itself to send the heartbeat by broadcasting the following intents.
com.google.android.intent.action.MCS_HEARTBEAT
com.google.android.intent.action.GTALK_HEARTBEAT
Hope this works for you.

Related

GCM only works 1 time after send heartbeat

I am facing a problem with using GCM as chat. User A can receive as many GCM as possible, if he does not reply. However, when User A tries to reply, after a few times both party sending message to each other, they will stop receiving GCM. I tried to look around and see a solution when sending Heartbeat every 2 minutes. However, after sending the Heartbeat, I will only receive GCM 1 more time until the next heartbeat is sent.
Currently, to fix this, I have to change network state (change to mobile network, or turn off then turn on Wifi again). How can I overcome this problem?

Setting scheduled push notification on GCM Server

Is it possible to set up a Scheduled Push notification from the GCM server.
Example:
As I click a button i send an api call to the GCM server to send me a push after 30min.
Is that possible?
If yes, please guide me.
Thanks in advance.
No, it's not possible. GCM server attempts to deliver the messages you send to it immediately.
If you want to schedule a message for delivery at a given time, schedule it in your server. i.e. make your server send it to GCM server after 30 minutes.

Receiving Messages in an Android GCM app, with a HTTP server (not CCS/XMPP)

I've scoured the internet and can't find an example of anyone trying to set up Push Messaging with GCM from an HTTP server. I've read through Google's example at http://developer.android.com/google/gcm/client.html and it looks like the BrodcastReceiver's onReceive() method is triggered when the app calls gcm.send(). So my question is, if I am not calling gcm.send() (since this is an HTTP server I'm working with), how does onReceive() get triggered?
You can simply ignore the client code in the demo that calls gcm.send(). The demo demonstrates both the device to cloud and cloud to device messaging. It triggers the communication in the client, which sends a message to the server via GCM CCS, which in turns sends the same message back to the app.
If you don't use the GCM CCS, you remove the gcm.send() part from the client code. Your server sends a message to GCM by an HTTP request. GCM server delivers the message to your device and the onReceive method of your broadcast receiver is triggered.

How to receive multi c2dm notifications?

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.

android push notification c2dm

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.

Categories

Resources