Skip to content

Commit 4c2f224

Browse files
committed
take care of more cases
1 parent 5f1b59b commit 4c2f224

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/android/com/adobe/phonegap/push/GCMIntentService.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,38 @@ protected void onMessage(Context context, Intent intent) {
9191
SharedPreferences prefs = context.getSharedPreferences(PushPlugin.COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
9292
boolean forceShow = prefs.getBoolean(FORCE_SHOW, false);
9393

94-
// if we are in the foreground, just surface the payload, else post it to the statusbar
94+
// if we are in the foreground and forceShow is `false` only send data
9595
if (!forceShow && PushPlugin.isInForeground()) {
9696
extras.putBoolean(FOREGROUND, true);
9797
PushPlugin.sendExtras(extras);
9898
}
99+
// if we are in the foreground and forceShow is `true`, force show the notification if the data has at least a message or title
100+
else if (forceShow && PushPlugin.isInForeground()) {
101+
extras.putBoolean(FOREGROUND, true);
102+
103+
showNotificationIfPossible(context, extras);
104+
}
105+
// if we are not in the foreground always send notification if the data has at least a message or title
99106
else {
100107
extras.putBoolean(FOREGROUND, false);
101108

102-
// Send a notification if there is a message
103-
String message = this.getMessageText(extras);
104-
String title = getString(extras, TITLE, "");
105-
if ((message != null && message.length() != 0) ||
106-
(title != null && title.length() != 0)) {
107-
createNotification(context, extras);
108-
}
109+
showNotificationIfPossible(context, extras);
109110
}
110111
}
111112
}
113+
114+
private void showNotificationIfPossible (Context context, Bundle extras) {
115+
116+
// Send a notification if there is a message or title, otherwise just send data
117+
String message = this.getMessageText(extras);
118+
String title = getString(extras, TITLE, "");
119+
if ((message != null && message.length() != 0) ||
120+
(title != null && title.length() != 0)) {
121+
createNotification(context, extras);
122+
} else {
123+
PushPlugin.sendExtras(extras);
124+
}
125+
}
112126

113127
public void createNotification(Context context, Bundle extras) {
114128
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@@ -214,7 +228,7 @@ public void createNotification(Context context, Bundle extras) {
214228
setNotificationCount(extras, mBuilder);
215229

216230
/*
217-
* Notication add actions
231+
* Notification add actions
218232
*/
219233
createActions(extras, mBuilder, resources, packageName);
220234

0 commit comments

Comments
 (0)