Setting up the back end for Google Cloud Messaging

I recently studied Android Development, and I'm trying to create an example application that uses Google Cloud Messaging. My goal is to create a simple application that can receive push notifications from the server. I received the client part of the application for work by registering my device. Now I am trying to create a server part. However, I have absolutely no experience in server setup or server-side programming. So I was hoping that someone could point me in the right direction so that I had a server sending push notifications. I follow the tutorial at this link , but I'm stuck in the server implementation. I would really appreciate it if someone could point me in the right direction. Thanks!

+6
source share
2 answers

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"

+6
source

If you used PHP, you should be familiar with xampp or similar software.

If not, all you have to do is download and install it, start the services in your browser too:

 http://localhost/xampp 

check the installation.

If you can see the Xampp page, you can run php scripts from xampp / htdocs and run them like this:

 http://localhost/yourscript.php 

Try the simple greeting world:

 <?php echo 'hello world'; ?> 

After that, you should be ready to start with this tutorial or any Google tutorial by simply typing gcm php tutorial

I found that php is the easiest way to configure the server side for GCM, hope you find this useful ...

+1
source

Source: https://habr.com/ru/post/949082/


All Articles