如何从状态栏中删除通知?

发布于 2024-09-01 08:41:58 字数 154 浏览 4 评论 0原文

我根据我的情况在状态栏中显示通知。到此为止,就OK了。

现在我的应用程序中的问题是当我返回应用程序时,状态栏中仍然显示通知

当我从应用程序返回时,我不希望收到通知。为此给我一些建议。

I am displaying a Notification in status bar depending up on my condition. Up to this, it is OK.

Now problem in my application is when I come back to application, still the Notification is displayed in the status bar.

I don't want the Notification when I come back from the application. For this give me some suggestions.

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

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

发布评论

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

评论(4

寄离 2024-09-08 08:41:58

我没有足够的代表来添加评论,所以 @Commonware 。 。 。如果您提供更具体的细节(例如告诉他们使用
“通知 ID”,当他们创建通知并使用该 ID 取消通知时。
如果您给出答案,请使其完整或至少提供完整的详细信息。这些帖子不仅适用于 OP,还可以帮助其他遇到这篇文章的人。
像这样

final NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE);

final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

然后取消它你打电话

notificationManager.cancel(NOTIFICATION_ID);

或者你可以打电话

notificationManager.cancelAll();

I don't have enough rep to add comment so @Commonware . . . it would be more helpful to future readers if you gave more specific details like telling them to use a
"notification id" when they create the notification and use that ID to cancel the notification.
If you give an answer make it complete or at least provide the full details. These posts are not only meant for the OP it helps others who come across this post as well.
like so

final NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE);

final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis());

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL;
Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0);

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent);
notificationManager.notify(NOTIFICATION_ID, notification);

Then to cancel it you call

notificationManager.cancel(NOTIFICATION_ID);

or you can call

notificationManager.cancelAll();
冰雪之触 2024-09-08 08:41:58

您可以通过 NotificationManager cancel() 自己的通知。由您决定何时cancel()它以及何时显示它。

You can cancel() your own Notifications via the NotificationManager. It is up to you to decide when to cancel() it and when to show it.

隱形的亼 2024-09-08 08:41:58
notificationManager.cancelAll();
notificationManager.cancelAll();
蓝天 2024-09-08 08:41:58
private void cancelNotificationInBar() {
        NotificationCreator notification = new NotificationCreator(getApplicationContext());
        notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        if (notification.mNotificationManager != null) {
            notification.mNotificationManager.cancelAll();
        }
    }
private void cancelNotificationInBar() {
        NotificationCreator notification = new NotificationCreator(getApplicationContext());
        notification.mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

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