In my Activity when the user says they want to enable notifications I call the following method:
private Intent buildRegistrationIntent(boolean register) {
String intentName = "com.google.android.c2dm.intent." + (register ? "REGISTER" : "UNREGISTER");
Intent intent = new Intent(intentName);
intent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); // boilerplate
intent.putExtra("sender", "[email protected]");
intent.putExtra("TEST", "test extras");
return intent;
}
In my C2DM BroadcastReceiver I have this:
@Override
public void onReceive(Context context, Intent intent) {
log.fine(Boolean.toString(intent.getExtras().containsKey("TEST")));
log.fine(Boolean.toString(intent.getExtras().containsKey("registration_id")));
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION")) {
handleRegistration(context, intent);
} else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
handleMessage(context, intent);
}
}
The problem is, the "TEST" extra never gets sent to the C2DM BroadcastReceiver. The output from the below lines is "False" then "True" i.e. it has the registration_id, but not TEST.
Is there any way to pass some user defined data to the BroadcastReceiver or does the C2DM infrastructure eat the original intent and create a new one with just the registration_id?
It looks like this is impossible. Whatever receives the REGISTER intent doesn't pass it on to onReceive.