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.68k stars 3.97k forks source link

πŸ› [firebase_messaging] VibrationPattern doesn't seems work when receiving background messages #5208

Closed Ted-chiptech closed 3 years ago

Ted-chiptech commented 3 years ago

Bug report

Describe the bug Hi, I created a AndroidNotificationChannel with a vibrationPattern value, the vibrationPattern doesn't seem to work when receiving the background messages. I can confirm the message does receive on the right notification channel as that notification channel has a different ring tone, but the vibrationPattern value is not applied. If I use FlutterLocalNotificationsPlugin to display a notification from that notification channel, it works.

Steps to reproduce

  1. Create a notification channel with vibrationPattern.

    final newChannel = AndroidNotificationChannel(
      'Channel 1',
      'Channel 1',
      'Channel 1 Description',
      importance: Importance.high,
      vibrationPattern: Int64List.fromList([4]),
    );
    
    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()
        ?.createNotificationChannel(
            newChannel );
  2. Switch app to background and send a notification message,(C# Example)

    var message = new Message
            {
                Notification = new Notification
                {
                    Body = "Test Message",
                    Title = "Test Message"
                },
                Data = new Dictionary<string, string>
                {
                    {"Foo", "Test Message"},
                },
                Token = registrationToken,
                Android = new AndroidConfig
                {
                    Priority = Priority.High,
                    Notification = new AndroidNotification
                    {
                        ChannelId = "Channel 1"
                    }
                },
                Apns = new ApnsConfig
                {
                    Headers = new Dictionary<string, string>
                    {
                        {"apns-priority", "10"}
                    },
                    Aps = new Aps
                    {
                        ContentAvailable = true
                    }
                }
            };
    
            await FirebaseMessaging.DefaultInstance.SendAsync(message);
  3. The app received the background message in onBackgroundMessage callback.
    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  4. It only makes one vibration.

Expected behavior

It should make continuous vibration as the vibrationPattern value is 4. https://developer.android.com/reference/android/app/Notification.html#FLAG_INSISTENT

Additional context


You would need flutter_local_notifications package to setup the android notification channel.

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.6, on Microsoft Windows [Version 10.0.19042.804], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.1) [!] 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. [√] VS Code (version 1.53.2) [√] Connected device (1 available) ```

Flutter dependencies

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

Click To Expand ``` Dart SDK 2.10.5 Flutter SDK 1.22.6 response_app 1.0.0+1 dependencies: - address_search_field 3.0.10 [flutter flutter_web_plugins http google_maps_flutter] - argon_buttons_flutter 1.0.6 [flutter] - cloud_firestore 0.16.0+1 [flutter meta quiver firebase_core firebase_core_platform_interface cloud_firestore_platform_inte rface cloud_firestore_web] - connectivity 2.0.2 [flutter meta connectivity_platform_interface connectivity_macos connectivity_for_web] - cupertino_icons 0.1.3 - dash_chat 1.1.15 [flutter flutter_parsed_text uuid intl transparent_image] - data_connection_checker 0.3.4 - dio 3.0.10 [http_parser path] - dio_http_cache 0.2.11 [flutter quiver json_serializable json_annotation dio sqflite path crypto] - enum_to_string 1.0.14 - equatable 1.2.5 [collection meta] - expandable 4.1.4 [flutter] - firebase_analytics 7.0.1 [meta flutter firebase_core firebase_analytics_web firebase_analytics_platform_interface] - firebase_auth 0.20.1 [meta firebase_core firebase_core_platform_interface firebase_auth_platform_interface firebase_auth_w eb flutter] - firebase_core 0.7.0 [firebase_core_platform_interface flutter quiver meta firebase_core_web] - firebase_crashlytics 0.4.0+1 [flutter stack_trace firebase_core firebase_core_platform_interface firebase_crashlytics_plat form_interface] - firebase_messaging 8.0.0-dev.15 [meta flutter firebase_core firebase_core_platform_interface firebase_messaging_platform_i nterface firebase_messaging_web] - firebase_performance 0.5.0+1 [flutter firebase_core] - firebase_remote_config 0.6.0 [flutter firebase_core] - flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine] - flutter_bloc 6.1.1 [flutter bloc provider] - flutter_form_builder 3.14.0-alpha.1 [flutter flutter_typeahead intl flutter_chips_input datetime_picker_formfield flutter_ colorpicker signature validators date_range_picker flutter_touch_spin image_picker image_picker_for_web rating_bar country_p ickers phone_number] - flutter_local_notifications 4.0.1+1 [flutter flutter_local_notifications_platform_interface platform timezone] - flutter_secure_storage 3.3.5 [meta flutter] - font_awesome_flutter 8.11.0 [flutter] - get_it 5.0.4 [async meta] - google_fonts 1.1.1 [flutter http path_provider crypto pedantic] - intl 0.16.1 [path] - intl_phone_number_input 0.5.2+2 [flutter meta libphonenumber equatable] - is_lock_screen 1.0.0 [flutter] - json_annotation 3.1.1 - notification_permissions 0.4.8 [flutter] - package_info 0.4.3+2 [flutter] - persistent_bottom_nav_bar 2.1.0 [flutter] - pin_code_fields 6.0.2 [flutter] - pull_to_refresh 1.6.2 [flutter] - qr_code_scanner 0.3.4 [flutter] - random_color 1.0.5 [flutter] - rxdart 0.24.1 - shared_preferences 0.5.12+4 [meta flutter shared_preferences_platform_interface shared_preferences_linux shared_preference s_macos shared_preferences_web shared_preferences_windows] - timeago_flutter 0.3.0 [timeago flutter] - tuple 1.0.3 [quiver] - url_launcher 5.7.10 [flutter url_launcher_platform_interface url_launcher_web url_launcher_linux url_launcher_macos url_la uncher_windows] - vibration 1.7.3 [flutter vibration_web] - volume 1.0.1 [flutter system_shortcuts] dev dependencies: - build_runner 1.10.12 [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 s helf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml] - flutter_flavorizr 1.0.9 [flutter archive args checked_yaml io json_annotation xml yaml] - flutter_spinkit 4.1.2+1 [flutter] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charc ode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data] - json_serializable 3.5.1 [analyzer build build_config json_annotation meta path source_gen] - lint 1.3.0 - test 1.16.0-nullsafety.5 [analyzer async boolean_selector coverage http http_multi_server io js node_preamble package_conf ig path pedantic pool shelf shelf_packages_handler shelf_static shelf_web_socket source_span stack_trace stream_channel type d_data web_socket_channel webkit_inspection_protocol yaml test_api test_core] transitive dependencies: - _fe_analyzer_shared 12.0.0 [meta] - analyzer 0.40.6 [_fe_analyzer_shared args cli_util collection convert crypto glob meta package_config path pub_semver sour ce_span watcher yaml] - archive 2.0.13 [crypto args path] - args 1.6.0 - async 2.5.0-nullsafety.1 [collection] - basic_utils 2.7.0-rc.4 [http logging json_annotation pointycastle convert crypto] - bloc 6.1.1 [meta] - boolean_selector 2.1.0-nullsafety.1 [source_span string_scanner] - build 1.6.1 [analyzer async convert crypto glob logging meta path] - build_config 0.4.5 [checked_yaml json_annotation meta path pubspec_parse yaml] - build_daemon 2.1.5 [built_collection built_value http_multi_server logging pedantic path pool shelf shelf_web_socket strea m_transform watcher web_socket_channel] - build_resolvers 1.5.2 [analyzer build crypto graphs logging meta path package_config pool pub_semver] - build_runner_core 6.1.6 [async build build_config build_resolvers collection convert crypto glob graphs 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.4 [json_annotation source_span yaml] - cli_util 0.2.0 [path] - clock 1.1.0-nullsafety.1 - cloud_firestore_platform_interface 3.0.2 [flutter meta collection firebase_core plugin_platform_interface] - cloud_firestore_web 0.3.0+2 [flutter flutter_web_plugins http_parser meta firebase_core firebase_core_web cloud_firestore_ platform_interface js] - 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] - country_pickers 1.3.0 [flutter] - coverage 0.14.2 [args logging package_config path source_maps stack_trace vm_service] - crypto 2.1.5 [collection convert typed_data] - dart_style 1.3.10 [analyzer args path source_span] - date_range_picker 1.0.6 [flutter] - datetime_picker_formfield 1.0.0 [flutter intl] - fake_async 1.2.0-nullsafety.1 [clock collection] - ffi 0.1.3 - file 5.2.1 [intl meta path] - firebase 7.3.3 [http http_parser js] - firebase_analytics_platform_interface 1.0.3 [flutter meta] - firebase_analytics_web 0.1.1 [flutter flutter_web_plugins firebase firebase_analytics_platform_interface meta] - firebase_auth_platform_interface 3.1.0 [flutter meta firebase_core plugin_platform_interface] - firebase_auth_web 0.3.3 [flutter flutter_web_plugins meta http_parser intl firebase_core firebase_core_web firebase_auth_p latform_interface js] - firebase_core_platform_interface 3.0.1 [flutter meta plugin_platform_interface quiver] - firebase_core_web 0.2.1+3 [firebase_core_platform_interface flutter flutter_web_plugins meta js] - firebase_crashlytics_platform_interface 1.1.6 [flutter meta collection firebase_core plugin_platform_interface] - firebase_messaging_platform_interface 1.0.0-dev.10 [flutter meta firebase_core plugin_platform_interface] - firebase_messaging_web 0.1.0-dev.6 [flutter flutter_web_plugins meta firebase_core firebase_core_web firebase_messaging_pl atform_interface js service_worker] - fixnum 0.10.11 - flutter_chips_input 1.9.5 [flutter] - flutter_colorpicker 0.3.5 [flutter] - flutter_keyboard_visibility 4.0.2 [meta flutter_keyboard_visibility_platform_interface flutter_keyboard_visibility_web flu tter] - flutter_keyboard_visibility_platform_interface 1.0.1 [flutter meta plugin_platform_interface] - flutter_keyboard_visibility_web 1.0.1 [flutter_keyboard_visibility_platform_interface flutter_web_plugins flutter] - flutter_local_notifications_platform_interface 2.0.0+1 [flutter plugin_platform_interface] - flutter_parsed_text 1.2.5 [flutter] - flutter_plugin_android_lifecycle 1.0.11 [flutter] - flutter_touch_spin 1.0.1 [flutter intl] - flutter_typeahead 1.9.3 [flutter flutter_keyboard_visibility] - flutter_web_plugins 0.0.0 [flutter characters collection meta typed_data vector_math] - glob 1.2.0 [async collection node_io path pedantic string_scanner] - google_maps_flutter 1.1.1 [flutter flutter_plugin_android_lifecycle google_maps_flutter_platform_interface] - google_maps_flutter_platform_interface 1.1.0 [flutter meta plugin_platform_interface stream_transform collection] - graphs 0.2.0 - 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_picker 0.6.7+22 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 0.1.0+2 [image_picker_platform_interface flutter flutter_web_plugins meta js] - image_picker_platform_interface 1.1.6 [flutter meta http plugin_platform_interface] - io 0.3.4 [charcode meta path string_scanner] - js 0.6.3-nullsafety.2 - libphonenumber 1.0.2 [flutter meta] - 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.1 [js] - node_io 1.2.0 [file node_interop path] - node_preamble 1.4.12 - package_config 1.9.3 [path charcode] - path 1.8.0-nullsafety.1 - path_provider 1.6.27 [flutter path_provider_platform_interface path_provider_macos path_provider_linux path_provider_windo ws] - path_provider_linux 0.0.1+2 [path xdg_directories path_provider_platform_interface flutter] - path_provider_macos 0.0.4+8 [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.10.0-nullsafety.2 - petitparser 3.1.0 [meta] - phone_number 0.6.3 [flutter] - platform 2.2.1 - plugin_platform_interface 1.0.3 [meta] - pointycastle 2.0.0 - pool 1.5.0-nullsafety.2 [async stack_trace] - process 3.0.13 [file intl meta path platform] - provider 4.3.2+3 [collection flutter nested] - pub_semver 1.4.4 [collection] - pubspec_parse 0.1.7 [checked_yaml json_annotation pub_semver yaml] - quiver 2.1.5 [matcher meta] - random_string 2.1.0 - rating_bar 0.2.0 [flutter] - 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_platfor m_interface path_provider_windows] - shelf 0.7.9 [async collection http_parser path stack_trace stream_channel] - shelf_packages_handler 2.0.0 [path shelf shelf_static] - shelf_static 0.2.9+1 [convert http_parser mime path shelf] - 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.10+1 [analyzer async build dart_style glob meta path pedantic source_span] - source_map_stack_trace 2.1.0-nullsafety.3 [path stack_trace source_maps] - source_maps 0.10.10-nullsafety.2 [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] - 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 - system_shortcuts 1.0.0 [flutter] - 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_sc anner term_glyph matcher] - test_core 0.3.12-nullsafety.5 [analyzer async args boolean_selector collection coverage glob io meta package_config path p edantic pool source_map_stack_trace source_maps source_span stack_trace stream_channel vm_service yaml matcher test_api] - timeago 2.0.29 - timezone 0.6.1 [path] - timing 0.1.1+3 [json_annotation] - transparent_image 1.0.0 - 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] - uuid 2.2.2 [crypto convert] - validators 2.0.1 [vin_decoder] - vector_math 2.1.0-nullsafety.3 - vibration_web 1.6.2 [flutter flutter_web_plugins] - vin_decoder 0.1.3 [meta basic_utils http random_string] - vm_service 5.5.0 [meta] - watcher 0.9.7+15 [async path pedantic] - web_socket_channel 1.1.0 [async crypto stream_channel] - webkit_inspection_protocol 0.7.4 [logging] - 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] ```

Thanks for your help!

markusaksli-nc commented 3 years ago

Hi @Ted-chiptech Why do you need to use flutter_local_notification for background messages? Why not use vibrateTimings? Thank you

Ted-chiptech commented 3 years ago

Hi @Ted-chiptech Why do you need to use flutter_local_notification for background messages? Why not use vibrateTimings? Thank you

Thanks a lot, @markusaksli-nc, that's exactly what I am after, I wasn't aware of that option as it's not available in the firebase-admin-dotnet library