C2DM: How to use C2D_MESSAGE permission?

The receivers they claim you need at the top in the summary appears to be a mistake in the documentation, as it does not match the manifest example.

“Receivers for com.google.android.c2dm.intent.C2D_MESSAGE and com.google.android.c2dm.intent.REGISTRATION.”)

I got the examples they give to work using simply the example manifest entries tweaked to match my particular application’s package name.

When the C2DM code in Android sends the broadcast out (or, rather, when it looks for potential receivers to send the broadcast to), it looks for:

Find broadcast receivers for Intent: com.google.android.c2dm.intent.REGISTRATION That have the permission: .permission.C2D_MESSAGE

All C2DM messages sent to your application by the Android C2DM code will be looking for that particular permission. It’s specific to your application, and simply needs to be in that structure (your application’s package + “.permission.C2D_MESSAGE”).

Regarding how the registration request gets the package name to use for the permissions, that is handled when you first register with the “app” extra – from the documentation:

“app is the application’s ID, set with a PendingIntent to allow the registration service to extract application information.”

the line in question:

registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate

Leave a Comment