flutter - 如何清除 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();
}

 

https://stackoverflow.com/questions/63562956/

相关文章:

python - 将 2 个不同年份的 .resample(D).size() 绘制到一张图表中?

java - 无法在 Linux 上的 Intellij 中指定 SDK

python - Django:使用 django-storage 从 S3 创建 zipfile

c# - 如何从 .NET Core 3.1 中的 DI 获取 SignalR IHubContex

python - 通过 Python 的 gRPC API 服务器无法工作

flutter - 如何使用计时器更新小部件

php - 带有 "sometimes"规则的 Laravel Validator 自定义消息

python - 对包含 str 和元组的 Pandas MultiIndex 进行排序

amazon-web-services - AWS API 网关上的剥离 header

python-3.x - TypeError : on heapq. heapop on pytho