Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Using Google Cloud Messaging with Cloud Endpoints

Google Cloud Messaging (GCM)allows your Cloud Endpoints to send notifications to registered Android devices whenever the state of a resource changes. For example, suppose a user uses a Note application from 2 devices: Device A and Device B. If the user is adding a note from Device A. Google Cloud Messaging can be used in the Cloud Endpoint for the insert operation to ping Device B to indicate that a note has been added.

To add GCM to an Endpoint:

  1. In the Google APIs Console, enable Google Cloud Messaging:

  2. In the Google APIs Console, create a server API key to enable App Engine to securely communicate with the Google Cloud Messaging Server:

  3. In the App Engine project, locate MessageEndpoint.java , which is a helper class for pinging all registered devices. Update MessageEndpoint.API_KEY to specify the API key obtained in the previous step.
  4. In the App Engine project, modify the generated Endpoint class to send pings to registered devices. To illustrate, refer to the following code snippet which would be inserted in the insertNote(Note) method to send a ping to all registered devices:
    MessageEndpoint.sendMessage(user.getEmail() + ":" + note.getId() + ":insert");
  5. In the Android project, locate GCMIntentService.java , which is a helper class for registering the device and performing actions when a message is received from GCM.
    1. Specify the Google APIs Project Number in GCMIntentService.java in the PROJECT_NUMBER field. The project number can be obtained from the URL to the API console dashboard for your project. For xample: https://code.google.com/apis/console/#project: your-project-number
    2. Modify GCMIntentService.onMessage() to handle the incoming GCM notification.
    3. In your Android project, call GCMIntentService.register(..) from your application (eg: in the onCreate() of your activity) to register the device with the Google Cloud Messaging Server and App Engine.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.