我在我的应用程序中使用推送通知。我需要在发送推送通知时显示通知。如果我发送另一个通知(没有清除之前的通知),它将替换旧通知。
这是我使用的代码:
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "New notification Pending";
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, time);
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
// Context context = getApplicationContext();
CharSequence contentTitle = "Notifications";
CharSequence contentText = newMessage;
Intent notificationIntent = new Intent(this, LoginActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
mNotificationManager.notify(1, notification);
但我不想替换通知,我想将其添加为新通知。
最佳答案
您还可以使用 System.currentTimeMillis() 为您的通知分配唯一 ID。
int id = (int) System.currentTimeMillis();
mNotificationManager.notify(id, notification);
关于android - 收到推送通知时添加新通知(不替换以前的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17148076/