Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 清除属于我的应用程序的已可见通知_Java_Android_Push Notification - Fatal编程技术网

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

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

我的应用程序使用Firebase云消息显示传入的推送通知。后端发送到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" 
    }
}
我的应用程序活动通过意向过滤器接收数据:

 <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();