Itβs actually easier to use Tomcat or AppEngine. See this GCM server setup guide.
You need the device registration identifier to which you want to send a message on the server side, you need your API key, this is an example of JSP:
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, you 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"
source share