firebase / flutterfire

šŸ”„ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.73k stars 3.98k forks source link

šŸ› [Firebase_messaging] No sound from push notifications on android devices #4555

Closed masfour7 closed 3 years ago

masfour7 commented 3 years ago

Bug report

Describe the bug The push notifications received on android devices have no sound, no vibration, and no pop-up is shown. I tried both, doing it manually using the Firebase console and using the server. I'm using firebase_messaging: ^8.0.0-dev.11 and its latest integration guide.

It doesn't work using the server with sound set to default (Node.js):

    const message = {
        notification: {
            title: title,
            body: body,
        },
        token: androidNotificationToken,
        data: {
            recipient: users[0],
            clickAction: "FLUTTER_NOTIFICATION_CLICK",
        },
        android: {
            priority: "high",
            notification: {
                sound: "default",
            },
        },
        apns: {
            payload: {
                aps: {
                    contentAvailable: true,
                    sound: "default",
                },
            },
        },
    };

    admin
        .messaging()
        .send(message)
        .then((response) => {
            // Response is a message ID string
            console.log("Successfully sent message", response);
            return null;
        })
        .catch((error) => {
            console.log("Error sending message", error);
            return null;
        });

Steps to reproduce

Steps to reproduce the behavior:

  1. Go to Firebase console - cloud messaging
  2. create a new notification
  3. make any configuration you want, and turn the sound to "Enabled". Then send it.
  4. The notification is received on android but with no sound or vibration.

Expected behavior

sound or vibration is heard when the notification is received.


Additional context

On iOS, everything is working. It's received with sound, vibration, and pop-up. I'm using VS Code for development. Tested this issue on Android 11 (Samsung Galaxy s20 & Xiaomi redmi note 9s). Also, I tried to create a new Flutter and Firebase project from a different PC but the same problem resists.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [āˆš] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18363.1256], locale en-US) ā€¢ Flutter version 1.22.5 at C:\flutter ā€¢ Framework revision 7891006299 (3 weeks ago), 2020-12-10 11:54:40 -0800 ā€¢ Engine revision ae90085a84 ā€¢ Dart version 2.10.4 [āˆš] Android toolchain - develop for Android devices (Android SDK version 30.0.2) ā€¢ Android SDK at C:\Users\masfo\AppData\Local\Android\sdk ā€¢ Platform android-30, build-tools 30.0.2 ā€¢ Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) ā€¢ All Android licenses accepted. [!] Android Studio (version 4.1.0) ā€¢ Android Studio at C:\Program Files\Android\Android Studio X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [āˆš] VS Code (version 1.52.1) ā€¢ VS Code at C:\Users\masfo\AppData\Local\Programs\Microsoft VS Code ā€¢ Flutter extension version 3.18.0 [āˆš] Connected device (2 available) ā€¢ SM G981U1 (mobile) ā€¢ RFCN504PREW ā€¢ android-arm64 ā€¢ Android 11 (API 30) ā€¢ sdk gphone x86 (mobile) ā€¢ emulator-5554 ā€¢ android-x86 ā€¢ Android 11 (API 30) (emulator) ```

Flutter dependencies

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

Click To Expand ``` dependencies: - cached_network_image 2.4.1 [flutter flutter_cache_manager octo_image] - camera 0.5.8+17 [flutter] - cloud_firestore 0.14.4 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_interface cloud_firestore_web] - cloud_functions 0.7.2 [meta flutter firebase_core firebase_core_platform_interface cloud_functions_platform_interface cloud_functions_web] - cupertino_icons 1.0.0 - datetime_picker_formfield 1.0.0 [flutter intl] - device_info 1.0.0 [flutter device_info_platform_interface] - file_picker 2.1.1 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface] - firebase_auth 0.18.4+1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_web flutter] - firebase_core 0.5.3 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_crashlytics 0.2.4 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface] - firebase_dynamic_links 0.6.3 [flutter firebase_core] - firebase_messaging 8.0.0-dev.11 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web] - firebase_storage 5.2.0 [flutter firebase_core firebase_core_platform_interface firebase_storage_web firebase_storage_platform_interface quiver] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_cache_manager 2.0.0 [flutter path_provider uuid http path sqflite pedantic clock file rxdart] - flutter_markdown 0.5.1 [flutter markdown meta path] - font_awesome_flutter 8.10.1 [flutter] - google_fonts 1.1.1 [flutter http path_provider crypto pedantic] - http 0.12.2 [http_parser path pedantic] - image 2.1.19 [archive xml meta] - image_cropper 1.3.1 [flutter] - image_picker 0.6.7+15 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - intl 0.16.1 [path] - path 1.8.0-nullsafety.1 - 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] - provider 4.3.2+3 [collection flutter nested] - scrollable_positioned_list 0.1.8 [flutter meta] - 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] - sqflite 1.3.2+1 [flutter sqflite_common path] - toast 0.1.5 [flutter] - 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] - video_player 1.0.1 [meta video_player_platform_interface video_player_web flutter] - video_trimmer 0.3.4 [flutter file_picker video_player flutter_ffmpeg video_thumbnail path_provider intl path] - wiredash 0.4.0 [flutter file http http_parser path_provider shared_preferences] dev dependencies: - flutter_launcher_icons 0.8.1 [image args yaml path] - 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] transitive dependencies: - 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] - characters 1.1.0-nullsafety.3 - charcode 1.2.0-nullsafety.1 - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 2.2.1 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.2.1+2 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_platform_interface js] - cloud_functions_platform_interface 3.0.3 [flutter meta firebase_core plugin_platform_interface] - cloud_functions_web 3.1.1 [firebase_core firebase_core_web cloud_functions_platform_interface flutter flutter_web_plugins http_parser meta js] - collection 1.15.0-nullsafety.3 - convert 2.1.1 [charcode typed_data] - crypto 2.1.5 [collection convert typed_data] - device_info_platform_interface 1.0.1 [flutter meta plugin_platform_interface] - 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.4 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.2+3 [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_crashlytics_platform_interface 1.1.4 [flutter meta collection firebase_core plugin_platform_interface] - firebase_messaging_platform_interface 1.0.0-dev.7 [flutter meta firebase_core plugin_platform_interface] - firebase_messaging_web 0.1.0-dev.2 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_platform_interface js service_worker] - firebase_storage_platform_interface 1.0.2 [flutter meta collection firebase_core plugin_platform_interface] - firebase_storage_web 0.1.1+1 [async crypto firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.5.0 [flutter meta] - flutter_ffmpeg 0.3.0 [flutter] - flutter_plugin_android_lifecycle 1.0.11 [flutter] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - http_parser 3.1.4 [charcode collection source_span string_scanner typed_data] - image_picker_platform_interface 1.1.1 [flutter meta http plugin_platform_interface] - js 0.6.2 - markdown 3.0.0 [args charcode meta] - matcher 0.12.10-nullsafety.1 [stack_trace] - meta 1.3.0-nullsafety.3 - mime 0.9.7 - nested 0.0.4 [flutter] - octo_image 0.3.0 [flutter flutter_blurhash] - 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] - process 3.0.13 [file intl meta path platform] - quiver 2.1.5 [matcher meta] - rxdart 0.24.1 - service_worker 0.2.4 [js] - 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] - sky_engine 0.0.99 - source_span 1.8.0-nullsafety.2 [charcode collection path term_glyph] - sqflite_common 1.0.2+1 [synchronized path meta] - stack_trace 1.10.0-nullsafety.1 [path] - stream_channel 2.1.0-nullsafety.1 [async] - 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] - 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] - vector_math 2.1.0-nullsafety.3 - video_player_platform_interface 2.2.0 [flutter meta] - video_player_web 0.1.4+1 [flutter flutter_web_plugins meta video_player_platform_interface] - video_thumbnail 0.2.5+1 [flutter] - 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] ```

markusaksli-nc commented 3 years ago

I'm not seeing this on the latest master 1.26.0-2.0.pre.168 with firebase_messaging: ^8.0.0-dev.11 using the official example but I only have an Android 11 emulator. Works on both emulator and Android 9 physical.

flutter doctor -v ``` [āˆš] Flutter (Channel master, 1.26.0-2.0.pre.168, on Microsoft Windows [Version 10.0.19041.685], locale et-EE) ā€¢ Flutter version 1.26.0-2.0.pre.168 at C:\Development\flutter_master ā€¢ Framework revision 299e017e41 (22 hours ago), 2021-01-03 06:29:01 -0500 ā€¢ Engine revision 121b67fb85 ā€¢ Dart version 2.12.0 (build 2.12.0-179.0.dev) [āˆš] Android toolchain - develop for Android devices (Android SDK version 30.0.2) ā€¢ Android SDK at C:\Users\marku\AppData\Local\Android\sdk ā€¢ Platform android-30, build-tools 30.0.2 ā€¢ Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283\jre\bin\java ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) ā€¢ All Android licenses accepted. [āˆš] Chrome - develop for the web ā€¢ Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [āˆš] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7) ā€¢ Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community ā€¢ Visual Studio Community 2019 version 16.7.30621.155 ā€¢ Windows 10 SDK version 10.0.18362.0 [āˆš] Android Studio (version 4.1.0) ā€¢ Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\201.6953283 ā€¢ Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter ā€¢ Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart ā€¢ Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [āˆš] Connected device (5 available) ā€¢ SM G950F (mobile) ā€¢ ce12171c51cc001c03 ā€¢ android-arm64 ā€¢ Android 9 (API 28) ā€¢ sdk gphone x86 arm (mobile) ā€¢ emulator-5554 ā€¢ android-x86 ā€¢ Android 11 (API 30) (emulator) ā€¢ Windows (desktop) ā€¢ windows ā€¢ windows-x64 ā€¢ Microsoft Windows [Version 10.0.19041.685] ā€¢ Chrome (web) ā€¢ chrome ā€¢ web-javascript ā€¢ Google Chrome 87.0.4280.88 ā€¢ Edge (web) ā€¢ edge ā€¢ web-javascript ā€¢ Microsoft Edge 87.0.664.66 ā€¢ No issues found! ```

Have you tried sending the notification through FCM directly?

masfour7 commented 3 years ago

I found the problem: the notification sound on my android phone was set to default (which was supposed to be the android default sound as for all other apps). However, the default sound for my flutter app is silent.

One solution I thought of is creating a notification channel for the sound and from there choose a specific sound for my app instead of the default one (which is silent). I still have not tested it.