Skip to content

Commit bee3992

Browse files
committed
"Parse" incoming data object when in background
1 parent 0985299 commit bee3992

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/android/com/plugin/gcm/GCMIntentService.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,29 @@ 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+
}
81+
catch (JSONException e) {}
82+
}
83+
84+
// Send a notification if there is a message
85+
if (message && message.length() != 0) {
86+
createNotification(context, extras);
87+
}
88+
}
89+
}
8090
}
8191

8292
public void createNotification(Context context, Bundle extras)

0 commit comments

Comments
 (0)