Connect My Exist Server To Gcm
I developed a client on android app and a server, but now I discovered the GMC- 'Google Cloud Messaging for Android' Is there any way to connect the GCM to my server, without chang
Solution 1:
You can send GCM messages from your Java Server. The simplest way is to use the server library supplied by Google (gcm-server.jar).
The code for sending a message is as simple as :
Sendersender=newSender(apiKey);
Messagemessage=newMessage.Builder()
.delayWhileIdle(true)
.addData("key1", "value1")
.addData("key2", "value2")
.build();
Resultresult= sender.send(message, registrationId, numOfRetries);
In addition, you'd have to check the result, to see if your message was accepted or rejected by GCM server.
This example shows how to send a message to a single device. There's a similar way to send the same message to multiple devices.
Finally, you'll have to implement some web service that accepts a registration ID from your app, and saves it in your DB.
Post a Comment for "Connect My Exist Server To Gcm"