0

I made a app with the PushPlugin

So far so good, I receive the notification as expected. But if i push 2+ notifications at the same time it will show the notifications in the status bar fine. But if I tap on the second(+) i will recieve the payload from the first notification.

I am looking a whole day now and cannot find it :(

Hope someone can help me out

Cordova 5

Plugins: Link

BTW: This happens on 1 event "coldstart"

peterdoesco.de
  • 529
  • 3
  • 19
  • Please see my [answer](http://stackoverflow.com/a/31040766/1761793). Do reply if it helps. – Ajoy Aug 03 '15 at 15:27
  • Also see this [answer](http://stackoverflow.com/a/29437083/1761793) – Ajoy Aug 03 '15 at 15:32
  • Thanks for the reply but this is not my problem. – peterdoesco.de Aug 04 '15 at 07:50
  • Did you try any of those? If all your notifications have the same notification id, Android will not know which message to pass to your application. – Ajoy Aug 04 '15 at 07:54
  • I do have notification is. In my description: So far so good, I receive the notification as expected. But if i push 2+ notifications at the same time it will show the notifications in the status bar fine. But if I tap on the second(+) i will recieve the payload from the first notification. – peterdoesco.de Aug 04 '15 at 07:56
  • *If the notification ID is not sent from your server, each notification is created with an ID 0. To fix this problem, you will have to set the notification ID for each notification you create. You can set the notification ID by sending a parameter notID from the server, with each notification, which will be used to create a notification.* – Ajoy Aug 04 '15 at 08:07
  • @Ajoy for the second time ;p i got notification ids. I "receive multiple notifications" – peterdoesco.de Aug 04 '15 at 08:09
  • Note: you will receive multiple notifications even though you don't give notification IDs. That is why I am asking you to confirm. Also I don't understand *i got notification ids*. If it is something important, please update your question with that info. – Ajoy Aug 04 '15 at 08:41
  • If I don't send notId with the payload it will result in only 1 notification because they will be overwritten, so you cannot receive multiple notifications if you don't give a notId (this is my experience). But updating the plugin didn't help either, because i already got the latest version. I'm stuck now. – peterdoesco.de Aug 04 '15 at 08:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/85081/discussion-between-peterdoesco-de-and-ajoy). – peterdoesco.de Aug 04 '15 at 08:44
  • Why is my question voted -1 ? :[ – peterdoesco.de Aug 06 '15 at 09:28

2 Answers2

0

The cause of this problem is in the GCMIntentService.java, the code was starting the app via:

PendingIntent contentIntent =  
  PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

which means it was always using the same requestCode. So the app was always using the first notification payload. The fix was to change the requestCode for each notification.

int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode,
  notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

We have fixed this issue in the new version of the PushPlugin which can be found at:

https://github.com/phonegap/phonegap-plugin-push

This is the version of the PushPlugin we announced at PhoneGap Day EU and it will be maintained as opposed to the version of the plugin you are currently using.

Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – JAL Aug 03 '15 at 19:11
  • @JAL Yeah, I thought of that when I answered it but I'm in the middle of the woods Ontario, Canada on edge network and will provide. Ore details when I get back to civilization. Just wanted to enable Peter to move forward. – Simon MacDonald Aug 03 '15 at 22:12
  • I think i already have the latest version (2.5.0) see screenshot? Is that right? – peterdoesco.de Aug 04 '15 at 08:11
  • com.phonegap.plugins.PushPlugin 2.5.0 "PushPlugin" – peterdoesco.de Aug 04 '15 at 08:13
  • np, try the new plugin. Raise issues! – Simon MacDonald Aug 04 '15 at 13:39
0

Found the fix here: https://github.com/phonegap-build/PushPlugin/issues/328

There was something different how the notId is handled

peterdoesco.de
  • 529
  • 3
  • 19