Skip to content

Commit 93ecf51

Browse files
authored
Merge pull request avivais#67 from quilligana/optional-multiple-notifications-android
Optional ability to override standard behaviour of a single notification in android notification tray
2 parents b63c63a + 74e51c0 commit 93ecf51

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Parse.Push plugin for Cordova/Phonegap/ionic. Works for both hosted Parse.com an
6161

6262
*Android*: to prevent flooding the notification tray, this plugin retains only the last PN with the same `title` field. For messages without the `title` field, the application name is used. A count of unopened PNs is shown.
6363

64+
You can override this feature, however, by adding the following to `config.xml`:
65+
66+
```xml
67+
<preference name="ParseMultiNotifications" value="true" />
68+
```
69+
6470

6571
#### Foreground vs. Background
6672

@@ -139,6 +145,13 @@ Create the following tags in `config.xml`:
139145
This is the same "senderId" to be used in your parse-server push configuration.
140146
-->
141147
<preference name="ParseGcmSenderId" value="gcm-sender-id" />
148+
149+
<!-- As standard, this plugin only shows the most recent PN in
150+
the android notifications tray along with a count of unopened
151+
PNs. If you would like to override this behaviour and show all
152+
PNs in the tray, then add this preference.
153+
If not, skip this preference -->
154+
<preference name="ParseMultiNotifications" value="true" />
142155
```
143156

144157
- For legacy Parse.com
@@ -149,6 +162,13 @@ Create the following tags in `config.xml`:
149162

150163
<!-- Do not replace this string value. It must be "PARSE_DOT_COM"-->
151164
<preference name="ParseServerUrl" value="PARSE_DOT_COM" />
165+
166+
<!-- As standard, this plugin only shows the most recent PN in
167+
the android notifications tray along with a count of unopened
168+
PNs. If you would like to override this behaviour and show all
169+
PNs in the tray, then add this preference.
170+
If not, skip this preference -->
171+
<preference name="ParseMultiNotifications" value="true" />
152172
```
153173

154174
You're all set. The plugin takes care of initializing Parse platform using the `config.xml` preferences mentioned above. It also saves your installation to the database automatically.

src/android/ParsePushConfigReader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public final class ParsePushConfigReader {
3333
// ParseClientKey is not required by parse server, but can be required by some environments
3434
private static final String parseClientKeyKey = "ParseClientKey";
3535

36-
3736
private List<String> supportedKeys = new ArrayList(Arrays.asList(parseAppIdKey, parseServerUrlKey));
3837
private Map<String, String> configs;
3938

src/android/ParsePushPluginReceiver.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import android.app.Notification;
1111
import android.app.NotificationManager;
1212

13+
import github.taivo.parsepushplugin.ParsePushConfigReader;
14+
import github.taivo.parsepushplugin.ParsePushConfigException;
15+
1316
import android.support.v4.app.NotificationCompat;
1417

1518
import android.net.Uri;
@@ -40,15 +43,24 @@ protected void onPushReceive(Context context, Intent intent) {
4043
// relay the push notification data to the javascript
4144
ParsePushPlugin.jsCallback( getPushData(intent) );
4245
} else {
43-
//
44-
// only create entry for notification tray if plugin/application is
45-
// not running in foreground.
46-
//
47-
// use tag + notification id=0 to limit the number of notifications on the tray
48-
// (older messages with the same tag and notification id will be replaced)
49-
NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
50-
notifManager.notify(getNotificationTag(context, intent), 0, getNotification(context, intent));
51-
46+
//
47+
// only create entry for notification tray if plugin/application is
48+
// not running in foreground.
49+
//
50+
// So first we check if the user has set the configuration to have multiple
51+
// notifications show in the tray (i.e. set <preference name="ParseMultiNotifications" value="true" />)
52+
ParsePushConfigReader config = new ParsePushConfigReader(context, null, new String[] {"ParseMultiNotifications"});
53+
String parseMulti = config.get("ParseMultiNotifications");
54+
if(parseMulti != null && !parseMulti.isEmpty() && parseMulti.equals("true")){
55+
// If the user wants multiple notifications in the tray, then we let ParsePushBroadcastReceiver
56+
// handle it from here
57+
super.onPushReceive(context, intent);
58+
} else {
59+
// use tag + notification id=0 to limit the number of notifications in the tray
60+
// (older messages with the same tag and notification id will be replaced)
61+
NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
62+
notifManager.notify(getNotificationTag(context, intent), 0, getNotification(context, intent));
63+
}
5264
//
5365
// A user with Android 5.0.1 reports that notif is not created in tray when
5466
// app is off (not background), trying method described here

0 commit comments

Comments
 (0)