Reputation: 7914
My app uses Firebase Cloud Messaging to show incoming push notifications. Notification payload sent to Fireboase by backend is like this:
{
"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"
}
}
My app activity receives data via Intent Filter:
<intent-filter>
<action android:name="MESSAGE_DETAILS"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
It works fine. If my app is in background or not running, Firebase shows notification, on notification tap, Android starts activity corresponding to intent filter.
However, I also need implement functionality similar to Gmail - I need all notifications to be cleared atuomatically after user runs app with launcher icon. So, how to clear notifications programatically?
Upvotes: 0
Views: 45
Reputation: 403
Just put the below code in the onCreate()
method of your launcher activity
NotificationManager notificationManager = (NotificationManager)
getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
Upvotes: 1