小编Fab*_*aro的帖子

Flutter:我无法以编程方式删除传入的 Firebase 通知

我的手机收到了一条传入的 Firebase 通知,如果用户没有点击它并且用户重新打开应用程序,我希望通过从通知有效负载收到的标签和 id_notification 以编程方式删除 Android 通知。

我使用了 Firebase_messaging "^1.0.1" Flutter 插件和 MessageHandler 来处理传入消息。

为了删除通知,我使用了平台渠道:

private boolean removeNotification(String tag, int idNotifica) {
    boolean result = false;
    NotificationManager notifManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notifManager.cancel(tag, idNotifica);
    result = true;
    return result;
  }
Run Code Online (Sandbox Code Playgroud)

但它不起作用,或者更确切地说,通知无法删除并且发生 PlatformException。

当我的手机收到 Firebase 通知后,我运行此平台通道代码来查看 StatusBarNotification:

  @RequiresApi(api = Build.VERSION_CODES.M)
  public String  getInfoAllNotification() {
    String info = "";
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    StatusBarNotification[] barNotifications = 
notificationManager.getActiveNotifications();
    for(StatusBarNotification notificationInStatusBar: barNotifications) {
      Notification n = notificationInStatusBar.getNotification();
      Bundle b = n.extras;
      if (b != null) …
Run Code Online (Sandbox Code Playgroud)

android firebase flutter firebase-cloud-messaging

6
推荐指数
0
解决办法
1204
查看次数