How can I receive notifications from the server on an Android device?

I am creating an application in which the user passes some information. I store this data in the database through servlets, that is, I call my own servlets, which will receive data via url and store them in the database. Therefore, I want other users of the same application to know that there is some information, and in turn they will receive information that another user has updated. For this we can use a survey or pusher. But polling will take a lot of battery power. I tried C2DM, but it does not work for me. So I’m thinking of some other mechanism with which I can implement, besides C2DM. Please suggest some way to work it. and for example if you come across.

+4
source share
1 answer

C2DM is outdated, a new version called Google Cloud Messaging (GCM) and exactly what you need for your use. There is even a GCM demo application that uses the Java servlet. The source code can be found here , view it directly, or if you prefer GitHub, you can use this repository .

Servlet code can be found in the file

samples/gcm-demo-server/src/com/google/android/gcm/demo/server/HomeServlet.java 

If you follow the instructions in the Getting Started manual, you will have a working application soon. I would advise you not to try to copy it together, you need to get a clear idea of ​​how the GCM architecture works.

+4
source

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


All Articles