Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up Server Side for Google Cloud Messaging

I've recently been learning Android Development and I am trying to make a sample application which uses Google Cloud Messaging. My goal is to make a simple application which can receive Push notifications from a server. I've gotten the client side of the application to work by registering my device. Now I am trying to create the server side. However, I have absolutely no experience in setting up a server or programming on the server side. So I was hoping someone could point me in the right direction so that I could have a server sending the Push notifications. I have been following the tutorial on this link but I am stuck at the server implementation. I would greatly appreciate it if someone could point me in the right direction. Thanks!

like image 918
Nick Richards Avatar asked Jul 10 '13 06:07

Nick Richards


1 Answers

Actually is more easier using Tomcat or AppEngine. See this tutorial in how to setup your GCM Server.

You need the device registration id to which you want to send the message on the server side you will need your API key, this is a JSP example :

http://yourdomain.com:8080/sendMessage.jsp?registrationID=kSADAS3242&messageToSend=Hello

String value = request.request.getParameter("messageToSend");
String registrationId = request.getParameter("registrationID");
Sender sender = new Sender("YOUR API KEY");
Message message = new Message.Builder().addData("FLAG","SERVE").addData("MSG", value).build();
Result result = sender.send(message, registrationId, 5);

On your client device should expect :

@Override
protected void onMessage(Context context, Intent intent) {
    Log.i(TAG, "Got a message from Google Cloud Messaging !!");
    String tag = intent.getExtras().getString("FLAG");
    String message = intent.getExtras().getString("MSG");
    Log.i(TAG, tag + " : " + message);
}

This should print "SERVE : Hello"

like image 200
RicardoM Avatar answered Sep 25 '22 23:09

RicardoM