0

我正在尝试在我的手机上接收多个通知。但是每次我发送通知时。以前的通知都会被新通知覆盖。我看了其他问题,他们说有多个Id's通知我也在这样做,但我没有'不知道我哪里错了。

这是我创建通知的方式。(它是在服务中创建的)。

private void GenerateNotification(String data)
{
    String ns=Context.NOTIFICATION_SERVICE;
    manager=(NotificationManager) getSystemService(ns);

    int icon=R.drawable.ic_launcher;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, data, when);
    notification.flags |=Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_SOUND;
    Context context = getApplicationContext();
    CharSequence contentTitle = "The Best Essay";
    CharSequence contentText = data;
    Intent notificationIntent = new Intent(this,MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    manager.notify(HELLO_ID, notification);
    HELLO_ID++;
}

HelloID 在哪里增加以接收具有唯一 ID 的多个通知。请告诉我我做错了什么。

4

1 回答 1

0

所以问题是你使用的意图每次都是一样的。如果您尝试使用与已显示通知中使用的 Intent 相同的 Intent 通知用户,则 android 会认为它们是重复的。这是因为单击时的每个通知最终都会做完全相同的事情(所以 android 就像“为什么我需要显示其中两个?”)。

要做的事情是说“嘿,我是否已经显示通知?如果是这样,我将创建一个新通知,它将覆盖当前通知,但传达一个事实,即我实际上要通知两件事关于”。考虑短信应用程序。当您收到第二条未读短信时,它会覆盖关于原始短信的第一个通知,并用一条通知替换它,告诉您您有两条新短信。有道理?

于 2012-07-26T16:31:52.320 回答