Use Google Cloud Messaging (GCM)
Google Cloud Messaging (GCM) is a free service that helps developers send data from servers to their Android applications. This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4KB of payload data (so apps like instant messaging can consume the message directly).
Create a Google API project
To use GCM, you need to obtain a long-lived token (simple API key). If you're an existing C2DM user, you can use your C2DM token instead.
To create a Google API project, follow these steps:
- Open the Google Developers Console.
- If you haven't created an API project yet, near the top of the screen, click Create Project.
- Type a project name.
- Click Create.
- Once the project has been created, a page appears that displays your project ID and project number.
- Example: Project Number 670330094152
- Take note of your project number. You’ll use it later as your GCM sender ID.
Developers will be able to sign-up for GCM for both Play and non-Play apps. However, GCM stats will be available for only published Google Play apps. To be able to see GCM stats in your Google Play Developer Console, associate the GCM Simple API Key or C2DM token with your Android application. Here’s how:
- Sign in to your Google Play Developer Console.
- Select an app.
- On the left menu, click Services & APIs.
- Click the Link a sender ID button.
- Type your GCM API key or C2DM client login token.
- Click Link.
Note that you can also revoke your key or a token through Google APIs console. After the key or token is revoked, you can continue to see GCM stats on your app's Statistics page in your Google Play Developer Console until you remove the GCM sender ID.
Types of statistics
- Invalid request: Messages failed during a request where we returned an error_code or non-200 http stats code to the third party.
- Sent: Messages successfully sent to device.
- Expired: Messages that reached their time-to-live (TTL) and expired.
- Collapsed: Messages that have a collapse key and have been collapsed by other incoming messages with the same collapse key.
- Stored: Messages that don’t belong to other statuses and are stored in our servers.
Changes to GCM dataFebruary 17, 2015: Delivered messages & expired state
The number of GCM messages described as "Delivered" was being underreported. Some "Delivered" messages were described as "Stored." These issues have been corrected for new data, but it wasn’t possible to retrospectively correct older statistics.
Note: The total number of messages was correct.
New expired state
A new message state of "Expired" has been added to GCM. The "Expired" state refers to messages that couldn’t be delivered before their time to live (ttl) expired and were discarded. Previously, these messages were included in the "Stored" message count.