如何清除Flutter中的Firebase通知?

问题描述

您好,我在Flutter应用程序中使用FirebaseMessaging接收通知。我的应用程序正常接收通知,并且在我的应用程序未运行时显示通知托盘中。

问题是: 我收到了一些有关我的应用程序的通知,这些通知添加通知托盘中。然后我从启动器中的应用程序图标导航了我的应用程序。在这里,我需要从通知托盘中清除与我的应用程序相关的所有通知

请给我一个建议。对于Flutter应用程序,该怎么做。

解决方法

请在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();
}