@@ -27,28 +27,22 @@ public GcmIntentService() {
2727 protected void onHandleIntent (Intent intent ) {
2828 Bundle extras = intent .getExtras ();
2929 GoogleCloudMessaging gcm = GoogleCloudMessaging .getInstance (this );
30- // The getMessageType() intent parameter must be the intent you received
31- // in your BroadcastReceiver.
30+
3231 String messageType = gcm .getMessageType (intent );
3332
34- if (!extras .isEmpty ()) { // has effect of unparcelling Bundle
35- /*
36- * Filter messages based on message type. Since it is likely that GCM
37- * will be extended in the future with new message types, just ignore
38- * any message types you're not interested in, or that you don't
39- * recognize.
40- */
33+ if (!extras .isEmpty ()) {
34+
4135 if (GoogleCloudMessaging .
4236 MESSAGE_TYPE_SEND_ERROR .equals (messageType )) {
4337 sendNotification ("Send error: " + extras .toString ());
4438 } else if (GoogleCloudMessaging .
4539 MESSAGE_TYPE_DELETED .equals (messageType )) {
4640 sendNotification ("Deleted messages on server: " +
4741 extras .toString ());
48- // If it's a regular GCM message, do some work.
4942 } else if (GoogleCloudMessaging .
5043 MESSAGE_TYPE_MESSAGE .equals (messageType )) {
5144 Log .i (TAG , "Completed work @ " + SystemClock .elapsedRealtime ());
45+
5246 // Post notification of received message.
5347 if (extras != null && extras .get ("message" ) != null ) {
5448 sendNotification (extras .get ("message" ).toString ());
@@ -61,9 +55,7 @@ protected void onHandleIntent(Intent intent) {
6155 GcmBroadcastReceiver .completeWakefulIntent (intent );
6256 }
6357
64- // Put the message into a notification and post it.
65- // This is just one simple example of what you might choose to do with
66- // a GCM message.
58+
6759 private void sendNotification (String msg ) {
6860 mNotificationManager = (NotificationManager )
6961 this .getSystemService (Context .NOTIFICATION_SERVICE );
0 commit comments