我已经包含了一个用于创建PendingIntent以及mNM.notify()方法的唯一ID。当我设置两个同时显示的通知时,它们不会同时显示。显示第一个通知,并显示第二个通知的时间。很多人都有这个问题,唯一的建议是提供唯一的ID。但那不起作用!请帮忙。下面是我的showNotification()方法。
private void showNotification() {
/*create intent for show notification details when user clicks notification*/
Intent intent =new Intent(getApplicationContext(), MainActivity.class);
Random random = new Random();
int id = random.nextInt();
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
// This is the 'title' of the notification
CharSequence title = "Reminder!" + id;
// This is the icon to use on the notification
int icon = R.drawable.ic_dialog_alert;
// This is the scrolling text of the notification
CharSequence text = task;
// What time to show on the notification
long time = System.currentTimeMillis();
Notification notification = new Notification(icon, text, time);
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this,id, intent, Intent.FLAG_ACTIVITY_NEW_TASK);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, title, text, contentIntent);
// Clear the notification when it is pressed
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Send the notification to the system.
mNM.notify((int)System.currentTimeMillis(), notification);
// Stop the service when we are finished
stopSelf();
}
答案 0 :(得分:0)
我没有尝试过这个不受支持的答案。
我认为您正在寻找.setOngoing(true)
用户无法取消此通知,因此我想操作系统也无法取消它。