通知仅在第一次时显示在通知区域中

发布于 2024-11-05 05:08:52 字数 708 浏览 5 评论 0原文

假设我的应用程序发布了一个带有文本“hello”的状态栏通知。 “你好”通知在通知区域中显示良好。
现在,如果我的应用程序再次发布“hello”,而第一个“hello”仍在通知区域中,则通知区域仍包含单个“hello”通知, 这也很好。
但现在,如果第一个“hello”通知从通知区域取消(删除),然后 第二个“你好”通知已发布,我希望通知区域显示 再次出现(第二个)“你好”通知,但它没有显示任何“你好”通知。

这是为什么?我该如何解决这个问题?

这就是我所做的: 在发布通知之前我总是: Intent.setAction(""+new Date().getTime()); 我创建了一个内容意图,如下所示:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, flag);

我尝试了“标志”的所有以下值,但没有一个可以解决问题:
1) PendingIntent.FLAG_ONE_SHOT
2) PendingIntent.FLAG_CANCEL_CURRENT
3) 0

通知标志始终设置为

notification.flags |= 
    Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

感谢

suppose my application posts a status bar notification with the text "hello".
that "hello" notification shows fine in the notification area.
now if my application posts "hello" again while the first "hello" is still in the notification area, the notification area still contains a single "hello" notification,
and that's fine too.
But now, if the first "hello" notification is canceled (removed) from the notification area and then
the 2nd "hello" notification is posted, i would expect the notification area to show
the (2nd) "hello" notification again, but it does not show any "hello" notification.

why is that and how can i get around this problem?

this is what i've done:
before posting a notification i always:
intent.setAction(""+new Date().getTime());
and i create a content intent as in:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, flag);

i tried all the following values for 'flag' but none of them solves the problem:
1) PendingIntent.FLAG_ONE_SHOT
2) PendingIntent.FLAG_CANCEL_CURRENT
3) 0

the notification flags are always set to

notification.flags |= 
    Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2024-11-12 05:08:52

我猜您的代码类似于下面的代码:

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

<some other code>

private static final int ID = 1;
mNotificationManager.notify(ID, notification);

如果是这样,请尝试将“ID”更改为每个通知的唯一性。

I'm guessing your code looks something like the code below:

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

<some other code>

private static final int ID = 1;
mNotificationManager.notify(ID, notification);

if so, try changing the 'ID' to be unique for each notification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文