Show multiple push notification in status bar in c

2019-03-30 17:40发布

问题:

I am successfully implement the push notification in cordova using this push plugin.

Everything works correctly, but the problem if multiple notifications are received only latest notification is available. I already referred this answer, but it uses older plugin.

Here is the code what i tried from the answer.

int notId=0;
try {
  notId = Integer.parseInt(extras.getString("notId"));
}
catch(NumberFormatException e) {
  Log.e(TAG, "Number format exception - Error parsing Notification ID: " + e.getMessage());
}
catch(Exception e) {
  Log.e(TAG, "Number format exception - Error parsing Notification ID" + e.getMessage());
}

notId++;
mNotificationManager.notify((String) appName, notId, mBuilder.build());

回答1:

The Phonegap PushPlugin separates multiple notifications by using the notId property of the notification as delivered from the GCM server.

What you need to do is make sure you generate the notifications with a unique notId property on your server, when you send the notification to the GCM service (not on the phone!!!)

(The notId property is a property on the notification data object, just like message and title).

I also want to warn you that the current version of the plugin, v2.4.0, has a bug, so when the user clicks on the notifications, your app will still only be notified with the data from the latest. There is a patch for that problem here: https://github.com/phonegap-build/PushPlugin/pull/333