Steno,
I'm glad you got it to work.
Now you've done the hardest part. For your app, you can use the GCM class helper the docs talk about (although, it won't appear in the list of extras for me) or you can code your own receiver, which is trivial.
I know this is off topic but here's what you need:
--- in your AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="yourpackage.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="yourpackage.C2D_MESSAGE"/>
// Replace yourpackage by your own package name.
--- In your service
public class MyService extends Service {
public static String BROADCAST_ACTION = "yourpackage.YourActivity.GCMALERT";
...
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
IntentFilter filter = new IntentFilter();
filter.addAction(MyService.BROADCAST_ACTION);
registerReceiver(receiver, filter);
}
@Override
public void onDestroy() {
unregisterReceiver(receiver);
super.onDestroy();
}
private BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String type = extras.getString("xxxx"); // this is what is in your "data" : { ... }
String msg = extras.getString("yyyy"); // this is what is in your "data" : { ... }
// Create notification here or do whatever you need
}
};
}
--- Receiver (which you need to have declared in your AndroidMAnifest.xml as per the documentation. The receiver is what does all the work.
public class GCMMessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Log.w("GCM", "Message Receiver called");
if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
Log.w("GCM", "Received message");
final String xxxx = intent.getStringExtra("xxxx");
final String yyyy = intent.getStringExtra("yyy");
Log.d("GCM", "dmControl: xxxx = " + xxxx);
Log.d("GCM", "dmControl: yyyy = " + yyyy);
if (xxxx.equals("something")) { // sends a notification to your service
Intent broadcast = new Intent();
broadcast.putExtra("yyyy", yyyy);
broadcast.putExtra("xxxx", xxxx);
broadcast.setAction(MyService.BROADCAST_ACTION);
context.sendBroadcast(broadcast);
return;
}
}
}
}
Of course this is just a rough draft of what you could do and you can do more complicated things but that should give you an idea.