Skip to content

Commit

Permalink
"Parse" incoming data object when in background
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenstolk committed Aug 4, 2015
1 parent 0985299 commit bee3992
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/android/com/plugin/gcm/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,29 @@ protected void onMessage(Context context, Intent intent) {
if (extras != null)
{
// if we are in the foreground, just surface the payload, else post it to the statusbar
if (PushPlugin.isInForeground()) {
if (PushPlugin.isInForeground()) {
extras.putBoolean("foreground", true);
PushPlugin.sendExtras(extras);
PushPlugin.sendExtras(extras);
}
else {
extras.putBoolean("foreground", false);

// Send a notification if there is a message
if (extras.getString("message") != null && extras.getString("message").length() != 0) {
createNotification(context, extras);
}
}
}
String message = extras.getString("message");

if (message === null) {
// Providers like Parse always send a 'data' as root object, so "Parse" that
try {
JSONObject object_example = new JSONObject(extras.getString("data"));
message = object_example.getString("alert");
}
catch (JSONException e) {}
}

// Send a notification if there is a message
if (message && message.length() != 0) {
createNotification(context, extras);
}
}
}
}

public void createNotification(Context context, Bundle extras)
Expand Down

0 comments on commit bee3992

Please sign in to comment.