我用下面的代碼來顯示通知如何在時間的Android應用程序
private void SendNotification(String notificationTitle, String notificationMessage)
{
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
android.app.Notification notification = new android.app.Notification(R.drawable.ic_launcher, notificationMessage,
System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.putExtra("notif_id", "5100");
//Setting the single top property of the notification and intent.
notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(MainActivity.this, notificationTitle, notificationMessage, pendingIntent);
notificationManager.notify((int)System.currentTimeMillis(), notification);
}
每當有新通知來只顯示一個通知,前一個應該被刪除,新的一應所示。
任何線索都會有所幫助。
Thanx in advance
o。
要取消前一個(如果存在的話),PendingIntent.getActivity(此,0,notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT),以取代額外只有PendingIntent.FLAG_UPDATE_CURRENT – AlexBcn
AlexBcn,嘗試了兩種選擇,他們都沒有刪除以前的消息。感謝您的迴應。 – osum