Google on Thursday announced it has brought its Google Cloud Messaging (GCM) service from Android to Chrome. The company is promising apps and extensions in the browser that leverage GCM will consume less bandwidth and use up less battery life on users’ machines.
If you don’t use a service like GCM, you can keep apps and extensions running efficiently by only responding to events such as timers or navigation to a particular site, as well as events that occur outside of Chrome by repeatedly polling a server. Google is offering GCM to alleviate this issue further, but users need to be signed into Chrome since the service relies on a push channel that’s only established for signed-in users (messages are automatically delivered to all the devices where the user has signed in and installed the given app or extension).
If you’re a developer, sending a message in your app or extension can be done by following these steps:
- Request a token (channel ID) via chrome.pushMessaging.getChannelId().
- Pass the returned token to your server.
- Whenever you need to send a message to your app or extension, post the message along with the token to the GCM server-side API.
Messages are then delivered in “near real-time” to Chrome. This makes the event page wake up (assuming it’s not already running) and the message is delivered to the app or extension’s chrome.pushMessaging.onMessage listener.
The GCM service handles all aspects of queuing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas.
This year’s Google conference is less than a week away, but apparently the company decided it didn’t want to delay the announcement any further. You can expect Google will be talking up both GCM for Android and GCM for Chrome at its event, likely with loads of examples for developers. If you can’t wait till then, sample apps are available on GitHub.
Top Image Credit: Wong Mei Teng