Describe the bug
I've set up firebase_messaging and I'm able to receive messages from FCM in general. All the callbacks work just fine both on Android and iOS except onMessage when app is in background state.
Message I'm sending (through postman):
{
"to": "<device token>",
"priority": "high",
"data": {
"id": 123,
"status": "some status",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"type": "AccountConfirmation"
}
}
Message is received when app is in foreground, but not when in background.
(Also funny fact - when in foreground this message is received as {notification: {title: null, body: null}, data: ...., but maybe its just how FCM sends these types of messages - with title and body present but set to null)
I've tried different versions of firebase_messaging package, 6.0.12 included.
Also worth mentioning that background messages (onBackgroundMessage ones, but as far as I understand that is not the same as onMessage callback in background state) work well if configured. I've tested with and without that config.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Application receives message from FCM
Flutter doctor
[√] Flutter (Channel dev, v1.15.3, on Microsoft Windows [Version 10.0.18363.657], locale en-US)
• Flutter version 1.15.3 at C:\flutter
• Framework revision 67826bdce5 (3 weeks ago), 2020-02-10 14:59:32 -0800
• Engine revision 6158f03ef5
• Dart version 2.8.0 (build 2.8.0-dev.8.0 514a8d4c84)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\admin\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 28.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.
[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
[√] VS Code (version 1.42.1)
• VS Code at C:\Users\amunk\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.8.1
[√] Connected device (1 available)
• AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• No issues found!
Hi @liri2006
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you
@iapicca cases are not the same. Issue that you linked is about onBackgroundMessage callback while mine is about onMessage.
Documentation on firebase_messaging states:

And I'm not getting onMessage called. Maybe I'm just understanding it wrong and onMessage should not be called when app is in background, but onBackgroundMessage should be used instead to handle those types of messages.
But if that's the case then documentation is quite misleading and should be fixed.
This issue still persists
Channel stable, v1.12.13+hotfix.8
firebase_messaging: ^6.0.12
for a data message - onMessage gets fired twice when the notification is triggered from API call
For data only, you need to set the message priority to "high" for android & set "content-available" for iOS, otherwise the devices class these as unimportant and ignore them if the app is in the background.
@Ehesp I tried your suggestion but now I'm getting triggered twice on "onMessage" per push notification like #1911
here's my config:
{
"token": [token],
"notification": {
"title": [title],
"body": [body],
},
"data": {
"some_data": [data]
},
"android": {
"notification": {
"sound": "default"
},
},
"apns": {
"headers": {
"apns-priority": 5,
},
"payload": {
"aps": {
"content-available": 1,
},
},
},
}
I can also confirm that this is not working with firebase_messaging: ^6.0.16
I'm using the following setup:
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.2, on Microsoft Windows [Version 10.0.18363.836], locale de-DE)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 4.0)
[√] Connected device (2 available)
await post('https://fcm.googleapis.com/fcm/send',
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=$serverToken',
},
body: jsonEncode(
<String, dynamic>{
'priority': 'high',
'data': <String, dynamic>{
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': await firebaseMessaging.getToken(),
},
),
);
If the app is in the foreground onMessage() is called. If the app is in the background (but not killed) onMessage() isn't called.
I solved this issue
https://github.com/FirebaseExtended/flutterfire/issues/2777#issuecomment-685805903
Most helpful comment
@iapicca cases are not the same. Issue that you linked is about onBackgroundMessage callback while mine is about onMessage.

Documentation on firebase_messaging states:
And I'm not getting onMessage called. Maybe I'm just understanding it wrong and onMessage should not be called when app is in background, but onBackgroundMessage should be used instead to handle those types of messages.
But if that's the case then documentation is quite misleading and should be fixed.