Java 清除属于我的应用程序的已可见通知
我的应用程序使用Firebase云消息显示传入的推送通知。后端发送到Fireboase的通知负载如下所示:Java 清除属于我的应用程序的已可见通知,java,android,push-notification,Java,Android,Push Notification,我的应用程序使用Firebase云消息显示传入的推送通知。后端发送到Fireboase的通知负载如下所示: { "to": "/topics/599_79", "priority": "high", "data": { "id_message": "209" "id_city": "599" } "notification" : { "body" : "New message test", "title" : "New message
{
"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"
}
}
我的应用程序活动通过意向过滤器接收数据:
<intent-filter>
<action android:name="MESSAGE_DETAILS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
它很好用。如果我的应用程序在后台或未运行,Firebase将显示通知,在通知点击时,Android将启动与意向过滤器对应的活动
然而,我还需要实现类似于Gmail的功能——我需要在用户运行带有启动器图标的应用程序后自动清除所有通知。
那么,如何以编程方式清除通知呢?只需将下面的代码放在启动程序活动的onCreate方法中
NotificationManager notificationManager = (NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();