1919public class GCMIntentService extends GCMBaseIntentService {
2020
2121 private static final String TAG = "GCMIntentService" ;
22-
22+
2323 public GCMIntentService () {
2424 super ("GCMIntentService" );
2525 }
@@ -64,19 +64,30 @@ protected void onMessage(Context context, Intent intent) {
6464 if (extras != null )
6565 {
6666 // if we are in the foreground, just surface the payload, else post it to the statusbar
67- if (PushPlugin .isInForeground ()) {
67+ if (PushPlugin .isInForeground ()) {
6868 extras .putBoolean ("foreground" , true );
69- PushPlugin .sendExtras (extras );
69+ PushPlugin .sendExtras (extras );
7070 }
7171 else {
7272 extras .putBoolean ("foreground" , false );
73-
74- // Send a notification if there is a message
75- if (extras .getString ("message" ) != null && extras .getString ("message" ).length () != 0 ) {
76- createNotification (context , extras );
77- }
78- }
79- }
73+ String message = extras .getString ("message" );
74+
75+ if (message == null ) {
76+ // Providers like Parse always send a 'data' as root object, so "Parse" that
77+ try {
78+ JSONObject object_example = new JSONObject (extras .getString ("data" ));
79+ message = object_example .getString ("alert" );
80+ extras .putString ("message" , message );
81+ }
82+ catch (JSONException e ) {}
83+ }
84+
85+ // Send a notification if there is a message
86+ if (message != null && message .length () != 0 ) {
87+ createNotification (context , extras );
88+ }
89+ }
90+ }
8091 }
8192
8293 public void createNotification (Context context , Bundle extras )
@@ -89,15 +100,15 @@ public void createNotification(Context context, Bundle extras)
89100 notificationIntent .putExtra ("pushBundle" , extras );
90101
91102 PendingIntent contentIntent = PendingIntent .getActivity (this , 0 , notificationIntent , PendingIntent .FLAG_UPDATE_CURRENT );
92-
103+
93104 int defaults = Notification .DEFAULT_ALL ;
94105
95106 if (extras .getString ("defaults" ) != null ) {
96107 try {
97108 defaults = Integer .parseInt (extras .getString ("defaults" ));
98109 } catch (NumberFormatException e ) {}
99110 }
100-
111+
101112 NotificationCompat .Builder mBuilder =
102113 new NotificationCompat .Builder (context )
103114 .setDefaults (defaults )
@@ -119,9 +130,9 @@ public void createNotification(Context context, Bundle extras)
119130 if (msgcnt != null ) {
120131 mBuilder .setNumber (Integer .parseInt (msgcnt ));
121132 }
122-
133+
123134 int notId = 0 ;
124-
135+
125136 try {
126137 notId = Integer .parseInt (extras .getString ("notId" ));
127138 }
@@ -131,20 +142,20 @@ public void createNotification(Context context, Bundle extras)
131142 catch (Exception e ) {
132143 Log .e (TAG , "Number format exception - Error parsing Notification ID" + e .getMessage ());
133144 }
134-
145+
135146 mNotificationManager .notify ((String ) appName , notId , mBuilder .build ());
136147 }
137-
148+
138149 private static String getAppName (Context context )
139150 {
140- CharSequence appName =
151+ CharSequence appName =
141152 context
142153 .getPackageManager ()
143154 .getApplicationLabel (context .getApplicationInfo ());
144-
155+
145156 return (String )appName ;
146157 }
147-
158+
148159 @ Override
149160 public void onError (Context context , String errorId ) {
150161 Log .e (TAG , "onError - errorId: " + errorId );
0 commit comments