我在 cordova 中成功实现了推送通知 using this push plugin .
一切正常,但如果收到多个通知,则问题只有最新的通知可用。我已经提到了this 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());
最佳答案
Phonegap PushPlugin 通过使用从 GCM 服务器传送的通知的 notId
属性来分隔多个通知。
您需要做的是确保在您的服务器上生成具有唯一 notId
属性的通知 ,当你向 GCM 服务发送通知时(不是在手机上!!!)
(notId 属性是通知数据对象上的一个属性,就像message
和title
一样)。
我还想警告你,当前版本的插件,v2.4.0,有一个错误,所以当用户点击通知时,你的应用程序仍然只会收到最新的数据通知。这里有针对该问题的补丁:https://github.com/phonegap-build/PushPlugin/pull/333
关于android - 在 cordova android 的状态栏中显示多个推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26975558/