[firebase_messaging]: Android: dismissing a notification delivers an empty RemoteMessage to onMessage (Firebase's NOTIFICATION_DISMISS broadcast is read as a message)
维护者通常 1 天内回复
评估
- 难度
- 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.onMessagefires 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
onBackgroundMessagereceives 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 ofFirebaseInstanceIdReceiver, checkswrapped_intentfirst. If it holds anIntent, the broadcast is a notification event: a dismissal goes toonNotificationDismissed(which logs the_ndanalytics event), and it is never handled as a message. FlutterFirebaseMessagingReceiveris registered for the same action, but has no such check. It goes straight tonew 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
- Use any app with firebase_messaging on Android that logs foreground messages, for example:
FirebaseMessaging.onMessage.listen((m) => debugPrint('onMessage ${m.toMap()}')); - Put the app in the background (Home).
- Send the device a notification message, i.e. one with a
notificationpayload (FCM v1:{"message": {"token": "<token>", "notification": {"title": "Test", "body": "Hello"}}}). Firebase displays it. - Open the app from the launcher, not by tapping the notification, so it is in the foreground.
- Pull down the notification shade and swipe the notification away, or tap "Clear all".
onMessagefires at once with the emptyRemoteMessageabove, 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 小时
- 30 天内合并 PR
- 72
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
firebase/flutterfire 的其他 Issue
-
Needs Attention type: bug
难度 4/5 3-5 天 新手友好度 42/100
firebase/flutterfire#18906 ·
维护者通常 1 天内回复
-
[cloud_firestore][Android]: query snapshots() can deliver an older snapshot after a newer one since 6.7.0可能已有人在做 @KafuiDumeloo 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 45/100
firebase/flutterfire#18904 ·
维护者通常 1 天内回复
-
🚀 [firebase_core] Bump Firebase JS SDK (13.1.0 → 13.2.0)可能已有人在做 @SelaseKay 于 1 天前认领。 未关闭Needs Attention type: enhancement
难度 1/5 1 小时以内 新手友好度 25/100
firebase/flutterfire#18902 · 1 条评论 ·
维护者通常 1 天内回复
-
Needs Attention type: bug
难度 3/5 1-2 天 新手友好度 35/100
firebase/flutterfire#18894 · 1 条评论 · 4 个 reaction ·
维护者通常 1 天内回复
-
Needs Attention platform: web plugin: auth type: bug
难度 3/5 1-2 天 新手友好度 48/100
firebase/flutterfire#18888 · 1 条评论 ·
维护者通常 1 天内回复
查看 firebase/flutterfire 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
MaikuB/flutter_local_notifications#2866 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
madeofpendletonwool/PinePods#1078 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
carp-dk/cognition_package#40 ·
-
难度 2/5 1-3 小时 新手友好度 86/100
daniel-pimenta-cc/ledor#58 ·
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复