[firebase_messaging]: Android: dismissing a notification delivers an empty RemoteMessage to onMessage (Firebase's NOTIFICATION_DISMISS broadcast is read as a message)

オープン
#18,897 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@akashdh11 がすでに取り組んでいます。

2026年11月3日 から。

  • #18898 @akashdh11 による — マージされずにクローズ
  • #18899 @akashdh11 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
android, dart, firebase

調査の方向性

Read FlutterFirebaseMessagingReceiver.onReceive in the Android implementation of firebase_messaging and compare its handling of wrapped_intent with Firebase's CloudMessagingReceiver. Reproduce by dismissing a notification while listening to FirebaseMessaging.onMessage; done means dismissals no longer deliver an empty RemoteMessage. The issue has two linked pull requests, including one still open.

索引モデルが issue の本文から書いたものです。

説明

Is there an existing issue for this?
  • I have searched the existing issues.

This is very likely the cause of #16954. That issue was closed as stale because nobody could reproduce it.

Which plugins are affected?

Messaging

Which platforms are affected?

Android

Description

On Android, FlutterFirebaseMessagingReceiver treats Firebase's own "notification dismissed" broadcast as a new message. Each time the user dismisses (swipes away, or "Clear all") a notification that the Firebase SDK displayed, the plugin builds a RemoteMessage from that broadcast. It has nothing in it:

{senderId: null, category: null, collapseKey: null, contentAvailable: false, data: {},
 from: null, messageId: null, messageType: null, mutableContent: false,
 notification: null, sentTime: 0, threadId: null, ttl: 0}
  • App in the foreground: FirebaseMessaging.onMessage fires with this empty message, once per dismissed notification. An app that draws its own notification for foreground messages (for example with flutter_local_notifications) shows a blank notification each time. Android lists it as "Custom app notification" in its notification history.
  • App in the background: the same empty message goes down the background path. From the receiver's code, that means onBackgroundMessage receives it when one is registered; our app registers none, so we see the plugin's "no onBackgroundMessage handler" warning instead.

Cause. firebase-messaging's CommonNotificationBuilder builds a displayed notification's delete intent as a com.google.android.c2dm.intent.RECEIVE broadcast to the app. The real com.google.firebase.messaging.NOTIFICATION_DISMISS intent sits inside it, in the wrapped_intent extra.

  • Google's CloudMessagingReceiver, the base of FirebaseInstanceIdReceiver, checks wrapped_intent first. If it holds an Intent, the broadcast is a notification event: a dismissal goes to onNotificationDismissed (which logs the _nd analytics event), and it is never handled as a message.
  • FlutterFirebaseMessagingReceiver is registered for the same action, but has no such check. It goes straight to new RemoteMessage(intent.getExtras()).

Proposed fix. In FlutterFirebaseMessagingReceiver.onReceive, ignore a broadcast whose wrapped_intent extra is an Intent, as CloudMessagingReceiver does. I'll open a PR.

Reproducing the issue
  1. Use any app with firebase_messaging on Android that logs foreground messages, for example:
    FirebaseMessaging.onMessage.listen((m) => debugPrint('onMessage ${m.toMap()}'));
    
  2. Put the app in the background (Home).
  3. Send the device a notification message, i.e. one with a notification payload (FCM v1: {"message": {"token": "<token>", "notification": {"title": "Test", "body": "Hello"}}}). Firebase displays it.
  4. Open the app from the launcher, not by tapping the notification, so it is in the foreground.
  5. Pull down the notification shade and swipe the notification away, or tap "Clear all".
  6. onMessage fires at once with the empty RemoteMessage above, once per dismissed notification.

Reproduced every time on:

  • a Pixel 11 Pro (Android 17, Google Play services 26.43.30), with the app installed from Play;
  • the Android 17 emulator (sdk_gphone16k_arm64), with a debug build.
Firebase Core version

4.15.2

Flutter Version

3.47.9

Relevant Log Output
# For each notification dismissed while the app is open:
D FLTFireMsgReceiver: broadcast received for message
I flutter : onMessage {senderId: null, ..., data: {}, messageId: null, notification: null, sentTime: 0, ...}
D FirebaseMessaging: Logging to scion event=_nd scionPayload=Bundle[{label=...}]

_nd is Firebase's notification_dismiss analytics event, logged by FirebaseInstanceIdReceiver for the same broadcast.

Flutter dependencies
  • firebase_messaging 16.7.1, firebase_core 4.15.2.
  • Android: firebase-messaging 25.1.3, play-services-cloud-messaging 17.4.0.
  • flutter_local_notifications 22.3.3, used to draw foreground notifications.

FlutterFirebaseMessagingReceiver.onReceive is the same in 17.0.1 and on main.

Additional context and comments

The FlutterFire docs' foreground example only draws a notification when message.notification != null. That is probably why most apps never notice: they silently ignore the empty message. It still reaches every onMessage listener, though, and every onBackgroundMessage handler.

主要言語
Dart
スター
9.3k
フォーク
4.1k
平均マージ
1日 15時間
マージ済み PR(30日)
72

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/flutterfire のほかの issue

firebase/flutterfire の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。