1

[解决了]

当我在寻找解决方案时,我突然灵光一闪:看到 Cordova 已更新,PushPlugin 也已更新。在我使用的版本中,我粘贴在问题中的片段不存在。

我更新了 Cordova 和插件......现在它可以通过使用后端的“notId”字段正常工作!;)

我将问题留在下面,以供更多读者阅读!

问候,

里克


我正在 Cordova/PhoneGap 中开发一个移动应用程序。我正在使用 PushPlugin ( https://github.com/phonegap-build/PushPlugin ) 来实现推送通知机制。

当我向我的设备发送多个推送时,我只能在 Android 设备上看到其中一个。iOS 设备在锁定屏幕中显示所有推送通知。

如何在 Android 中显示多个通知?我在插件的文档中进行了搜索,并在“onMessage”方法中找到了以下代码段:

[...]
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());
}

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

我试图在后端设置不同的'notId'字段,但它似乎不起作用......

还有什么想法吗?

谢谢你的帮助,里克。

4

3 回答 3

0

为 notId 使用随机数,这将起作用,例如:

   Random rnd = new Random();  
   int notId = rnd.nextInt(100);  

代替 :

    int notId = 0;
于 2015-01-05T11:50:09.183 回答
0
Use this :
    notificationManager.notify((String)appName,(int) Calendar.getInstance()
                .getTimeInMillis(), mBuider.build()); //What you are doing wrong is setting each notification same id so they are replacing one another and this code create new id by time , so you can see multiple notification on the screen 
于 2014-10-07T10:37:04.887 回答
0

您必须更改通知 ID,因为这始终不是解决方案是您必须使用随机数概念

Random random = new Random();
int randomNumber = random.nextInt(9999 - 1000) + 1000;
notificationManager.notify(randomNumber, notification);
于 2016-04-06T06:11:02.623 回答