How to clear firebase notification in Flutter?

Viewed 820

Hi am using FirebaseMessaging in my Flutter application to receive notifications. My application is receiving notification properly and displaying in notification tray when my app is not running.

The problem is: I received some notification for my application and those are added in notification tray. Then i navigated my application from application icon from launcher. Here i need to clear all the notifications related to my application from notification tray.

Please advice me one this. How to do it for Flutter application.

1 Answers

Please try this in MainActivity.java

import android.app.NotificationManager;
import android.content.Context;
 
@Override
protected void onResume() {
    super.onResume();

    // Removing All Notifications
    cancelAllNotifications();
}

private void cancelAllNotifications() {
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}

 
Related