Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0cd45030b2
Fetching contributors…

Cannot retrieve contributors at this time

83 lines (51 sloc) 2.133 kb

C2DM - Google Cloud to Device Messaging Service

c2dm sends push notifications to Android devices via Google c2dm.


$ gem install c2dm


An Android device running 2.2 or newer, its registration token, and a Google account registered for c2dm.


First you will need to authorize with google to get your ClientLogin auth token.

Use the credentials for the app you've registered with Google.

C2DM.authorize("", "password")

This sets auth_token for future requests.

You can also use cURL to get the AUTH= parameter:

# curl -X POST -d Email=<email> -d Passwd=<password> -d accountType=HOSTED_OR_GOOGLE -d service=ac2dm

We suggest you store the token and set it in your config files:

C2DM.auth_token = "YOUR_AUTH_TOKEN"

You can also set it in your environment:


If you'd like to set a custom source param for debugging, set:

ENV["C2DM_AUTH_TOKEN"] = "CompanyName-AppName-1.0"

Send a notification

Send a single notification:

  :registration_id => "...",
  :message => "Hi!",
  :extra_data => 42,
  :collapse_key => "some-collapse-key"

The only required key is :registration_id. You may also pass :collapse_key, but it's optional.

All other keys will be sent as "data.<key>". This is the payload of your notification.

Sending Multiple

You can also send multiple notifications at once.

notifications = [
    :registration_id => "...", 
    :message => "Hi!",
    :extra_data => 42
    :registration_id => "...", 
    :message => "Bye!",
    :extra_data => "BOOM",
    :collapse_key => "some-collapse-key"



  • Send multiple notifications concurrently using Typhoeus::Hyrda


  • Copyright (c) 2010 Amro Mousa, (c) 2011 Brandon Keene. See LICENSE.txt for details.
Jump to Line
Something went wrong with that request. Please try again.