gpt4 book ai didi

android - 从状态栏中删除通知图标

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:49:17 24 4
gpt4 key购买 nike

我在状态栏中显示一个图标。现在我想在打开该内容时立即删除该图标,一段时间后如果我们收到任何警报,该图标将再次显示。我该怎么做?

最佳答案

使用 NotificationManager 取消通知。您只需提供您的通知 ID。

https://developer.android.com/reference/android/app/NotificationManager.html

private static final int MY_NOTIFICATION_ID= 1234;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;
mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(MY_NOTIFICATION_ID, notification);

示例代码不完整。这取决于您如何创建通知。只需确保使用与创建通知时相同的 ID 取消通知即可。

取消:

mNotificationManager.cancel(MY_NOTIFICATION_ID);

关于android - 从状态栏中删除通知图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2839727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com