Android 通知不会消失(即使使用 Auto_Cancel)

发布于 2024-11-01 19:31:40 字数 754 浏览 1 评论 0原文

我有不同的通知,每个通知都有与之关联的不同捆绑包/活动。我的问题是它们一旦点击就不会消失。不过,它们并没有受到持续的通知,并且“清除”可以消除它们。下面是我的代码。任何想法将不胜感激。 :)

 private void showNotification(Bundle b){
    CharSequence myText = b.getString("notifStr");

    Notification notification = new Notification(R.drawable.stat_sample, myText,System.currentTimeMillis());

    Intent i = new Intent(myContext, NewPlace.class);
    i.setAction(Intent.ACTION_VIEW + Integer.toString(b.getInt("id")));
    i.putExtras(b);

    PendingIntent contentIntent = PendingIntent.getActivity(myContext, 0, i, 0);

    notification.defaults |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(myContext, myText,myText, contentIntent);

    notifMan.notify(b.getInt("id"), notification);
}

I have different notifications that each have a different bundle/activity associated with them. My problem is that they don't disappear once clicked. They aren't under ongoing notifications though and "clear" gets rid of them. Bellow is my code. Any thoughts would be greatly appreciated. :)

 private void showNotification(Bundle b){
    CharSequence myText = b.getString("notifStr");

    Notification notification = new Notification(R.drawable.stat_sample, myText,System.currentTimeMillis());

    Intent i = new Intent(myContext, NewPlace.class);
    i.setAction(Intent.ACTION_VIEW + Integer.toString(b.getInt("id")));
    i.putExtras(b);

    PendingIntent contentIntent = PendingIntent.getActivity(myContext, 0, i, 0);

    notification.defaults |= Notification.FLAG_AUTO_CANCEL;

    notification.setLatestEventInfo(myContext, myText,myText, contentIntent);

    notifMan.notify(b.getInt("id"), notification);
}

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

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

发布评论

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

评论(2

话少情深 2024-11-08 19:31:40

尝试更改:

notification.defaults |= Notification.FLAG_AUTO_CANCEL;

通知

notification.flags |= Notification.FLAG_AUTO_CANCEL;

文档(标志)

公共 int 默认值

自:API 级别 1 指定
值应取自
默认值。要设置,或所需的
默认声音、默认振动、
DEFAULT_LIGHTS。对于所有默认的
值,使用 DEFAULT_ALL。

try changing:

notification.defaults |= Notification.FLAG_AUTO_CANCEL;

to

notification.flags |= Notification.FLAG_AUTO_CANCEL;

Notification Documentation (Flags)

public int defaults

Since: API Level 1 Specifies which
values should be taken from the
defaults. To set, OR the desired from
DEFAULT_SOUND, DEFAULT_VIBRATE,
DEFAULT_LIGHTS. For all default
values, use DEFAULT_ALL.

轮廓§ 2024-11-08 19:31:40

你应该尝试

notification.flags |= Notification.FLAG_AUTO_CANCEL;

You should try

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