Connecting with the Disconnected - Adam Lowry - Keeping it Realtime, 2011-11-07
C2DM: Registration
Intent registrationIntent = new
Intent("com.google.android.c2dm.intent.REGISTER");
registrationIntent.putExtra("app",
PendingIntent.getBroadcast(ctx, 0, new Intent(), 0));
registrationIntent.putExtra("sender", "
[email protected]");
ctx.startService(registrationIntent);
public class C2DMPushReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(
"com.google.android.c2dm.intent.REGISTRATION")) {
String registration = intent.getStringExtra(
"registration_id");
String error = intent.getStringExtra("error");
String unregistered = intent.getStringExtra(
"unregistered");
setResult(Activity.RESULT_OK, null, null);
Android communicates with system daemons and apps via intents, same
for c2dm
you send a register intent, saying “here’s my sender ID, send me a
registration ID to use”
The receiver implements onReceive, and listens for the registration
intent, and get the registration id -- or an error. Just like APNS, you need
to send this registration ID to the server. It can change at any time; C2DM
can send this intent to tell you to change the id.