gpt4 book ai didi

java - 清除属于我的应用程序的已可见通知

转载 作者:行者123 更新时间:2023-12-02 11:41:17 24 4
gpt4 key购买 nike

我的应用使用 Firebase Cloud Messaging 来显示传入的推送通知。后端发送到Fireboase的通知负载如下:

{
"to": "/topics/599_79",
"priority": "high",
"data": {
"id_message": "209"
"id_city": "599"
}

"notification" : {
"body" : "New message test",
"title" : "New message"
"click_action": "MESSAGE_DETAILS"
}
}

我的应用程序 Activity 通过 Intent 过滤器接收数据:

 <intent-filter>
<action android:name="MESSAGE_DETAILS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>

效果很好。如果我的应用程序在后台或未运行,Firebase 会显示通知,点击通知后,Android 会启动与 Intent 过滤器相对应的 Activity 。

但是,我还需要实现类似于 Gmail 的功能 - 我需要在用户使用启动器图标运行应用程序后自动清除所有通知。那么,如何以编程方式清除通知?

最佳答案

只需将以下代码放入启动器 Activity 的 onCreate() 方法

NotificationManager notificationManager = (NotificationManager) 
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();

关于java - 清除属于我的应用程序的已可见通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48523666/

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