【问题标题】:How to clear firebase notification in Flutter?如何在 Flutter 中清除 Firebase 通知?
【发布时间】:2020-12-13 04:58:03
【问题描述】:

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

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

请给我一个建议。 Flutter 应用如何做。

【问题讨论】:

    标签: flutter push-notification firebase-cloud-messaging


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。其实我正在寻找 Flutter 中的解决方案。
    • 在 Flutter @RaghuMudem 中找到解决方案了吗?
    • @Sujal,是的,flutter 没有直接的方法。我在 android 和 iOS 入口点都添加了清晰的通知代码。这些将在启动时清除所有与应用相关的通知。
    猜你喜欢
    • 1970-01-01
    • 2019-09-26
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    相关资源
    最近更新 更多