Flutterfire: 馃悰 [firebase_messaging: 8.0.0-dev.9] Unable to receive foreground notification

Created on 29 Nov 2020  路  7Comments  路  Source: FirebaseExtended/flutterfire

Bug report

When receiving a notification whilst the app is in the foreground, the console logs D/FLTFireMsgReceiver( 5473): broadcast received for message but nothing happens. It worked well when I still had the old version 7.0.3.
Background notifications work fine!

Code

Here is my code:
FirebaseMessagingService exists as a Singleton and listenToMessages is called after Firebase was initialized.

class FirebaseMessagingService {

  void listenToMessages() {
    FirebaseMessaging.onMessage.listen((RemoteMessage message) {
      Fimber.d("onMessage $message");
      onMessage(message);
    });

    FirebaseMessaging.onBackgroundMessage(onFirebaseBackgroundMessage);
  }

}

Additional context

Here is my console output. You can see broadcast received for message when the foreground notification is received. Sadly the notification is not relayed to Flutter.

I/flutter ( 5473): 
W/ConnectionTracker( 5473): Exception thrown while unbinding
W/ConnectionTracker( 5473): java.lang.IllegalArgumentException: Service not registered: lp@f9ba507
W/ConnectionTracker( 5473):     at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1757)
W/ConnectionTracker( 5473):     at android.app.ContextImpl.unbindService(ContextImpl.java:1874)
W/ConnectionTracker( 5473):     at android.content.ContextWrapper.unbindService(ContextWrapper.java:792)
W/ConnectionTracker( 5473):     at ci.f(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):1)
W/ConnectionTracker( 5473):     at ci.d(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):2)
W/ConnectionTracker( 5473):     at lq.D(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):10)
W/ConnectionTracker( 5473):     at lc.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):2)
W/ConnectionTracker( 5473):     at ee.run(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):3)
W/ConnectionTracker( 5473):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/ConnectionTracker( 5473):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker( 5473):     at ix.run(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):6)
D/FLTFireMsgReceiver( 5473): broadcast received for message
W/m.zappr.androi( 5473): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (greylist,test-api, reflection, allowed)
W/m.zappr.androi( 5473): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (greylist,test-api, reflection, allowed)
W/m.zappr.androi( 5473): Accessing hidden method Landroid/os/WorkSource;->get(I)I (greylist, reflection, allowed)
W/m.zappr.androi( 5473): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (greylist, reflection, allowed)

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand

Doctor summary (to see all details, run flutter doctor -v):
[鈭歖 Flutter (Channel stable, 1.22.2, on Microsoft Windows [Version 10.0.19041.572], locale fr-FR)

[鈭歖 Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[!] Android Studio (version 4.1.0)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[鈭歖 Connected device (1 available)

! Doctor found issues in 1 category.

Android Studio currently has a bug with dectecting the plugins.


Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand

Dart SDK 2.10.2
Flutter SDK 1.22.2
zappr 1.0.0+1

dependencies:
- better_player 0.0.34 [flutter open_iconic_flutter wakelock pedantic meta flutter_widget_from_html_core flutter_hls_parser visibility_detector path_provider]
- cached_network_image 2.3.3 [flutter flutter_cache_manager octo_image]
- connectivity 2.0.2 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web]
- contacts_service 0.4.6 [flutter collection quiver]
- cupertino_icons 0.1.3
- dio 3.0.10 [http_parser path]
- fimber 0.4.4
- firebase_auth 0.18.3+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter]
- firebase_core 0.5.2+1 [firebase_core_platform_interface flutter quiver meta firebase_core_web]
- firebase_dynamic_links 0.6.2 [flutter firebase_core]
- firebase_messaging 8.0.0-dev.9 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface]
- floor 0.17.0 [path sqflite sqflite_common_ffi floor_annotation meta flutter]
- flushbar 1.10.4 [flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_better_camera 0.6.1 [flutter]
- flutter_cache_manager 1.4.2 [flutter path_provider uuid http path sqflite pedantic clock file rxdart]
- flutter_facebook_login 3.0.0 [flutter collection]
- flutter_image_compress 0.7.0 [flutter]
- flutter_linkify 3.1.3 [flutter linkify]
- flutter_localizations 0.0.0 [flutter intl characters collection meta path typed_data vector_math]
- flutter_staggered_animations 0.1.2 [flutter]
- flutter_svg 0.19.1 [flutter meta path_drawing vector_math xml]
- flutter_video_info 1.0.1 [flutter path]
- functional_widget_annotation 0.8.0
- gen_lang 0.1.3 [args path ansicolor]
- geocoder 0.2.1 [meta flutter]
- geolocator 6.1.6 [flutter geolocator_platform_interface]
- get_it 4.0.4 [async meta]
- google_sign_in 4.5.6 [google_sign_in_platform_interface flutter meta google_sign_in_web]
- googleapis 0.55.0 [_discoveryapis_commons http]
- image_cropper 1.3.1 [flutter]
- image_editor_pro 1.0.6 [flutter cupertino_icons zoom_widget font_awesome_flutter image_picker path_provider image_gallery_saver permission_handler dio screenshot signature flutter_colorpicker]
- intl 0.16.1 [path]
- json_annotation 3.1.0
- mailto 1.0.0 [meta]
- path_provider 1.6.24 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windows]
- permission_handler 5.0.1+1 [flutter meta permission_handler_platform_interface]
- photo_manager 0.6.0-dev.6 [flutter]
- photo_view 0.10.2 [flutter]
- property_change_notifier 0.2.0 [flutter]
- provider 4.3.2+2 [flutter nested collection]
- random_string 2.1.0
- retrofit 1.3.4+1 [meta dio]
- share 0.6.5+4 [meta mime flutter]
- shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preferences_macos shared_preferences_web shared_preferences_windows]
- url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_launcher_windows]
- uuid 2.2.2 [crypto convert]
- vector_math 2.1.0-nullsafety.3
- video_compress 2.1.0 [flutter]

dev dependencies:
- build_runner 1.10.4 [args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style glob graphs http_multi_server io js logging meta mime path pedantic pool pub_semver pubspec_parse shelf shelf_web_socket st
ack_trace stream_transform timing watcher web_socket_channel yaml]
- floor_generator 0.17.0 [analyzer build code_builder meta source_gen build_config collection dartx floor_annotation]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]
- functional_widget 0.8.0 [functional_widget_annotation source_gen build_config code_builder build analyzer meta]
- json_serializable 3.5.0 [analyzer build build_config json_annotation meta path source_gen]
- retrofit_generator 1.4.0+1 [dio source_gen built_collection code_builder tuple retrofit analyzer dart_style build]

dependency overrides:
- analyzer 0.41.0 [_fe_analyzer_shared args cli_util collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]

transitive dependencies:
- _discoveryapis_commons 0.2.0 [http]
- _fe_analyzer_shared 13.0.0 [meta]
- ansicolor 1.0.5
- archive 2.0.13 [crypto args path]
- args 1.6.0
- async 2.5.0-nullsafety.1 [collection]
- boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner]
- build 1.5.0 [analyzer async convert crypto logging meta path glob]
- build_config 0.4.2 [checked_yaml json_annotation meta path pubspec_parse yaml]
- build_daemon 2.1.4 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 1.4.3 [analyzer build crypto graphs logging meta path package_config pool pub_semver]
- build_runner_core 6.0.3 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pedantic pool timing watcher yaml]
- built_collection 4.3.2 [collection quiver]
- built_value 7.1.0 [built_collection collection fixnum quiver]
- characters 1.1.0-nullsafety.3
- charcode 1.2.0-nullsafety.1
- checked_yaml 1.0.2 [json_annotation source_span yaml]
- cli_util 0.2.0 [path]
- clock 1.1.0-nullsafety.1
- code_builder 3.5.0 [built_collection built_value collection matcher meta]
- collection 1.15.0-nullsafety.3
- connectivity_for_web 0.3.1+4 [connectivity_platform_interface flutter_web_plugins flutter]
- connectivity_macos 0.1.0+7 [flutter]
- connectivity_platform_interface 1.0.6 [flutter meta plugin_platform_interface]
- convert 2.1.1 [charcode typed_data]
- crypto 2.1.5 [collection convert typed_data]
- csslib 0.16.2 [source_span]
- dart_style 1.3.9 [analyzer args path source_span]
- dartx 0.5.0 [collection path crypto characters time meta]
- fake_async 1.2.0-nullsafety.1 [clock collection]
- ffi 0.1.3
- file 5.2.1 [intl meta path]
- firebase_auth_platform_interface 2.1.3 [flutter meta firebase_core plugin_platform_interface]
- firebase_auth_web 0.3.2+1 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_platform_interface js]
- firebase_core_platform_interface 2.1.0 [flutter meta plugin_platform_interface quiver]
- firebase_core_web 0.2.1+1 [firebase_core_platform_interface flutter flutter_web_plugins meta js]
- firebase_messaging_platform_interface 1.0.0-dev.6 [flutter meta firebase_core plugin_platform_interface]
- fixnum 0.10.11
- floor_annotation 0.10.0 [meta]
- flutter_blurhash 0.5.0 [flutter meta]
- flutter_colorpicker 0.3.4 [flutter]
- flutter_hls_parser 1.0.0 [flutter collection meta quiver]
- flutter_plugin_android_lifecycle 1.0.11 [flutter]
- flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math]
- flutter_widget_from_html_core 0.5.1+4 [flutter html]
- font_awesome_flutter 8.10.0 [flutter]
- geolocator_platform_interface 1.0.8 [flutter meta plugin_platform_interface vector_math]
- glob 1.2.0 [async collection node_io path pedantic string_scanner]
- google_sign_in_platform_interface 1.1.2 [flutter meta quiver]
- google_sign_in_web 0.9.2 [google_sign_in_platform_interface flutter flutter_web_plugins meta js]
- graphs 0.2.0
- html 0.14.0+4 [csslib source_span]
- http 0.12.2 [http_parser path pedantic]
- http_multi_server 2.2.0 [async]
- http_parser 3.1.4 [charcode collection source_span string_scanner typed_data]
- image 2.1.19 [archive xml meta]
- image_gallery_saver 1.6.5 [flutter]
- image_picker 0.6.7+14 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface]
- import_js_library 1.0.2 [flutter html flutter_web_plugins js]
- io 0.3.4 [charcode meta path string_scanner]
- js 0.6.2
- linkify 2.1.0
- logging 0.11.4
- matcher 0.12.10-nullsafety.1 [stack_trace]
- meta 1.3.0-nullsafety.3
- mime 0.9.7
- nested 0.0.4 [flutter]
- node_interop 1.2.0 [js]
- node_io 1.1.1 [node_interop path]
- octo_image 0.3.0 [flutter flutter_blurhash]
- open_iconic_flutter 0.3.0 [flutter]
- package_config 1.9.3 [path charcode]
- path 1.8.0-nullsafety.1
- path_drawing 0.4.1+1 [vector_math meta path_parsing flutter]
- path_parsing 0.1.4 [vector_math meta]
- path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter]
- path_provider_macos 0.0.4+6 [flutter]
- path_provider_platform_interface 1.0.4 [flutter meta platform plugin_platform_interface]
- path_provider_windows 0.0.4+3 [path_provider_platform_interface meta path flutter ffi win32]
- pedantic 1.9.2 [meta]
- permission_handler_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- petitparser 3.1.0 [meta]
- platform 2.2.1
- plugin_platform_interface 1.0.3 [meta]
- pool 1.4.0 [async stack_trace]
- process 3.0.13 [file intl meta path platform]
- pub_semver 1.4.4 [collection]
- pubspec_parse 0.1.5 [checked_yaml json_annotation pub_semver yaml]
- quiver 2.1.5 [matcher meta]
- rxdart 0.24.1
- screenshot 0.1.1 [path_provider flutter]
- shared_preferences_linux 0.0.2+4 [file flutter meta path path_provider_linux shared_preferences_platform_interface]
- shared_preferences_macos 0.0.1+11 [shared_preferences_platform_interface flutter]
- shared_preferences_platform_interface 1.0.4 [meta flutter]
- shared_preferences_web 0.1.2+7 [shared_preferences_platform_interface flutter flutter_web_plugins meta]
- shared_preferences_windows 0.0.1+3 [shared_preferences_platform_interface flutter ffi file meta path path_provider_platform_interface path_provider_windows]
- shelf 0.7.9 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 0.2.3 [shelf web_socket_channel stream_channel]
- signature 3.2.0 [flutter image]
- sky_engine 0.0.99
- source_gen 0.9.8 [analyzer async build dart_style glob meta path pedantic source_span]
- source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph]
- sqflite 1.3.2+1 [flutter sqflite_common path]
- sqflite_common 1.0.2+1 [synchronized path meta]
- sqflite_common_ffi 1.1.1 [sqlite3 sqflite_common synchronized path meta]
- sqlite3 0.1.8 [collection ffi meta]
- stack_trace 1.10.0-nullsafety.1 [path]
- stream_channel 2.1.0-nullsafety.1 [async]
- stream_transform 1.2.0
- string_scanner 1.1.0-nullsafety.1 [charcode source_span]
- synchronized 2.2.0+2
- term_glyph 1.2.0-nullsafety.1
- test_api 0.2.19-nullsafety.2 [async boolean_selector collection meta path source_span stack_trace stream_channel string_scanner term_glyph matcher]
- time 1.3.0
- timing 0.1.1+2 [json_annotation]
- tuple 1.0.3 [quiver]
- typed_data 1.3.0-nullsafety.3 [collection]
- url_launcher_linux 0.0.1+4 [flutter]
- url_launcher_macos 0.0.1+9 [flutter]
- url_launcher_platform_interface 1.0.9 [flutter meta plugin_platform_interface]
- url_launcher_web 0.1.5+1 [url_launcher_platform_interface flutter flutter_web_plugins meta]
- url_launcher_windows 0.0.1+3 [flutter]
- visibility_detector 0.1.5 [flutter]
- wakelock 0.2.1+1 [flutter meta wakelock_platform_interface wakelock_web]
- wakelock_platform_interface 0.1.0+1 [flutter meta]
- wakelock_web 0.1.0+3 [flutter flutter_web_plugins import_js_library js wakelock_platform_interface]
- watcher 0.9.7+15 [async path pedantic]
- web_socket_channel 1.1.0 [async crypto stream_channel]
- win32 1.7.4 [ffi]
- xdg_directories 0.1.2 [meta path process]
- xml 4.5.1 [collection convert meta petitparser]
- yaml 2.2.1 [charcode collection string_scanner source_span]
- zoom_widget 0.1.3 [flutter]


messaging bug

Most helpful comment

Service not registered has been popping up all over the place recently

All 7 comments

Hi @themadmrj
What is the payload you are using for the message. Does it also not work if you just run the official example?
FYI there is already a large open issue regarding not receiving notifications at all/properly with the dev version on iOS https://github.com/FirebaseExtended/flutterfire/issues/4097
Thank you.

Thnx for the quick reply @markusaksli-nc.
As you suggested, I tested the payload in detail with the official example. Turns out the notification is received in the foreground if the payload only contains string elements. So after converting every object (including ints, lists, maps) to a string, it worked. I think that should be fixed since it works whilst the app is in the background. It's not the expected bahaviour and works fine when using Firebase Messaging natively.

As for this bug :

W/ConnectionTracker( 5473): Exception thrown while unbinding
W/ConnectionTracker( 5473): java.lang.IllegalArgumentException: Service not registered: lp@f9ba507
W/ConnectionTracker( 5473):     at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1757)
W/ConnectionTracker( 5473):     at android.app.ContextImpl.unbindService(ContextImpl.java:1874)
W/ConnectionTracker( 5473):     at android.content.ContextWrapper.unbindService(ContextWrapper.java:792)
W/ConnectionTracker( 5473):     at ci.f(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):1)
W/ConnectionTracker( 5473):     at ci.d(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):2)
W/ConnectionTracker( 5473):     at lq.D(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):10)
W/ConnectionTracker( 5473):     at lc.a(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):2)
W/ConnectionTracker( 5473):     at ee.run(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):3)
W/ConnectionTracker( 5473):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
W/ConnectionTracker( 5473):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker( 5473):     at ix.run(:com.google.android.gms.dynamite_measurementdynamite@[email protected] (150700-0):6)

It also arises in the official example when adding

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    GeneratedPluginRegistrant.registerWith(flutterEngine);
  }

to MainActivity.java. Any idea how to fix it?

Service not registered has been popping up all over the place recently

@themadmrj That is a known issue https://github.com/FirebaseExtended/flutterfire/issues/4090

Could you paste the previous payload that was not working (omitting the FCM token of course)?
Non-string values shouldn't affect anything. This payload works just fine for me for example.

{
  "notification": {
    "title": "This is a title",
    "body": "This is the body"
  },
  "data": {
    "id": 1,
    "boolean": true
  },
  "priority": "normal",
  "to": "FCM Token"
}

They were all data messages, not notification. The following did not work for me with the official example:

{
  "data": {
    "id": 15,
    "type": "comment"
  }
}

Works for me using the official example.

I/flutter (18912): {data: {id: 15, type: comment}, messageId: 0:1606823172988654%a9039156f9fd7ecd, sentTime: 1606823172974, from: 486685679562, ttl: 2419200}

What are you using to send the notification?

I don't get it.
I just tested again with the official example, Android Studio 4.1 + emulator android api 30.
I changed the constructFCMPayload method to the following:

/// The API endpoint here accepts a raw FCM payload for demonstration purposes.
String constructFCMPayload(String token) {
  _messageCount++;
  return jsonEncode({
    'token': token,
    'data': {
      'via': 'FlutterFire Cloud Messaging!!!',
      'count': _messageCount,
    },
/*    'notification': {
      'title': 'Hello FlutterFire!',
      'body': 'This notification (#$_messageCount) was created via FCM!',
    },*/
  });
}

This does not work for me. The notification is sent, but not received by the FirebaseMessaging.onMessage.listen((RemoteMessage message) {} method.
Then, as I change 'count': _messageCount, to 'count': _messageCount.toString(),, the notification is received nicely in Flutter as well.

Edit: Actually Log.d(TAG, "broadcast received for message"); is not called, so the notification is not received by the device.

Was this page helpful?
0 / 5 - 0 ratings