我正在开发一个应用程序。我想向状态栏区域显示多个通知。但每次它都显示以前的消息。我尝试了很多东西,但它不起作用,如何在Android状态栏中显示多个通知。
以下是我的代码:
private void Notify(String Title, String Message)
{
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
@SuppressWarnings("deprecation")
Notification notification = new Notification(R.drawable.ic_launcher,Title, System.currentTimeMillis());
Log.e("NotificationManager","notify");
Intent notificationIntent = new Intent(getBaseContext(), NoteEdit.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
Log.e("NotificationManager","notificationIntent");
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(getBaseContext(), Title,Message, pendingIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(NOTIFICATION_ID , notification);
}
}
答案 0 :(得分:0)
在0的位置使用它,你必须使用一个变量并每次递增
PendingIntent contentIntent = PendingIntent.getActivity(getBaseContext(),
index++, notificationIntent, PendingIntent.FLAG_ONE_SHOT);