Skip to content

🐛 [firebase_messaging] playing sound when phone is in silent mode or vibrate mode #7787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
priyesh-bit opened this issue Jan 5, 2022 · 8 comments
Labels
closed-by-bot platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: no-response Customer did not respond after some time. Stale Issue with no recent activity type: bug Something isn't working

Comments

@priyesh-bit
Copy link

Bug report

Describe the bug
Ive added push notification custom sound and issue is sound is playing when phone is in silent mode or vibrate mode.

Steps to reproduce

Steps to reproduce the behavior:

  1. Ive added .wav file into raw and given NotificationManager.IMPORTANCE_HIGH | NotificationManager.IMPORTANCE_DEFAULT

MainActivity.kt

import android.app.NotificationChannel
import android.app.NotificationManager
import android.media.AudioAttributes
import android.net.Uri
import android.os.Build
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine


class MainActivity : FlutterActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val soundUri = Uri.parse("android.resource://" + applicationContext.packageName + "/" + R.raw.notification)
            val audioAttributes = AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                    .setUsage(AudioAttributes.USAGE_ALARM)
                    .build()

            val channel = NotificationChannel("high_importance_channel",
                    "High Importance Notifications", NotificationManager.IMPORTANCE_HIGH)
            channel.setSound(soundUri, audioAttributes)
            val notificationManager = getSystemService<NotificationManager>(NotificationManager::class.java)
            notificationManager.createNotificationChannel(channel)
        }
    }
}

main.dart

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  channel = AndroidNotificationChannel(
    'high_importance_channel',
    'High Importance Notifications',
    description: 'This channel is used for important notifications.',
    playSound: true,
    enableLights: true,
    sound: RawResourceAndroidNotificationSound('notification'),
  );

  flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  const AndroidInitializationSettings initializationSettingsAndroid =
      AndroidInitializationSettings('@drawable/ic_notification');
  final IOSInitializationSettings initializationSettingsIOS =
      IOSInitializationSettings(
          onDidReceiveLocalNotification: onDidReceiveLocalNotification);
  final InitializationSettings initializationSettings = InitializationSettings(
      android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
  flutterLocalNotificationsPlugin.initialize(initializationSettings,
      onSelectNotification: (String? payload) async {
    print("onSelectNotification Called");
    if (payload != null) {
      PushNotificationResponse pushData =
          pushNotificationResponseFromJson(payload);
      handleLocalNotificationClick(pushData);
    }
  });

  await flutterLocalNotificationsPlugin
      .resolvePlatformSpecificImplementation<
          AndroidFlutterLocalNotificationsPlugin>()
      ?.createNotificationChannel(channel);

  await FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
    alert: true,
    badge: true,
    sound: true,
  );

  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    print("onMessage Called");
    PushNotificationResponse pushData =
        pushNotificationResponseFromMap(message.data);
   (notification != null && android != null) {
      flutterLocalNotificationsPlugin.show(
        notification.hashCode,
        notification.title,
        notification.body,
        NotificationDetails(
          android: AndroidNotificationDetails(
            channel.id,
            channel.name,
            icon: '@drawable/ic_notification',
            playSound: true,
            color: ColorRes.primaryColor,
            enableLights: true,
            sound: RawResourceAndroidNotificationSound('notification'),
          ),
          iOS: IOSNotificationDetails(
            presentSound: true,
            presentBadge: true,
            presentAlert: true,
          ),
        ),
        payload: pushNotificationResponseToJson(pushData),
      );
    }
  });

  FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) async {
    print("onMessageOpenedApp Called ");
  });

  FirebaseMessaging.instance
      .getInitialMessage()
      .then((RemoteMessage? message) async {
    print("getInitialMessage Called ");
  });
  1. Sending push notification using API
{
    "to" : "FCM TOKEN",
    "data":{
        "body":"Test Notification !!!",
        "title":"Test Title !!!"
    },
    "notification":{
      "sound":"notification",
      "title":"My Title",
      "body":"My body"
   }
}
  1. See incorrect behavior about notification sound

Expected behavior

It should not play sound while silent mode

Let me know if im missing anything.

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, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] Connected device (3 available)

• No issues found!


Flutter dependencies

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

Click To Expand
Dart SDK 2.14.4
Flutter SDK 2.5.3
thecanadianhomes 1.0.0+1

dependencies:
- audioplayers 0.20.1 [uuid path_provider http flutter flutter_web_plugins]
- bot_toast 4.0.1 [flutter]
- cached_network_image 3.2.0 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- carousel_slider 4.0.0 [flutter]
- charts_flutter 0.12.0 [charts_common collection flutter intl logging meta]
- contacts_service 0.6.3 [flutter collection quiver]
- cupertino_icons 1.0.4
- device_info_plus 3.2.0 [flutter device_info_plus_platform_interface device_info_plus_linux device_info_plus_macos device_info_plus_web device_info_plus_windows]
- file_picker 4.3.0 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path]
- firebase_analytics 9.0.4 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 1.10.6 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.4.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_in_app_messaging 0.6.0+5 [firebase_core firebase_core_platform_interface firebase_in_app_messaging_platform_interface flutter meta]
- firebase_messaging 11.2.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_performance 0.8.0+3 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- flutter_google_places 0.3.0 [flutter google_api_headers google_maps_webservice http rxdart]
- flutter_linkify 5.0.2 [flutter linkify]
- flutter_local_notifications 9.1.5 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_map 0.14.0 [async collection flutter http intl latlong2 meta positioned_tap_detector_2 proj4dart transparent_image tuple vector_math]
- flutter_map_marker_cluster 0.4.4 [flutter flutter_map latlong2 flutter_map_marker_popup]
- flutter_map_tappable_polyline 3.1.0 [flutter flutter_map latlong2 positioned_tap_detector_2]
- flutter_osm_plugin 0.26.1 [flutter flutter_plugin_android_lifecycle stream_transform location url_launcher dio uuid flutter_osm_interface]
- flutter_phone_direct_caller 2.1.0 [flutter]
- flutter_pusher_client 0.3.1 [json_annotation flutter]
- flutter_rating_bar 4.0.0 [flutter]
- flutter_share 2.0.0 [flutter]
- flutter_svg 1.0.0 [flutter meta path_drawing vector_math xml]
- geocoding 2.0.1 [flutter geocoding_platform_interface]
- geolocator 8.0.1 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web]
- get 4.6.1 [flutter]
- get_it 7.2.0 [async collection]
- get_storage 2.0.3 [flutter get path_provider]
- google_place 0.4.3 [http]
- http 0.13.4 [async http_parser meta path]
- image_picker 0.8.4+4 [flutter flutter_plugin_android_lifecycle image_picker_for_web image_picker_platform_interface]
- in_app_review 2.0.3 [flutter in_app_review_platform_interface]
- injectable 1.5.0 [get_it]
- intl 0.17.0 [clock path]
- laravel_echo 0.2.8 [flutter]
- latlong2 0.8.1 [intl]
- location 4.3.0 [flutter location_platform_interface location_web]
- package_info_plus 1.3.0 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- percent_indicator 3.4.0 [flutter]
- perfect_volume_control 1.0.5 [flutter]
- permission_handler 8.3.0 [flutter meta permission_handler_platform_interface]
- reorderables 0.4.2 [flutter]
- sms_autofill 2.2.0 [pin_input_text_field flutter]
- stacked 2.2.7+1 [flutter get_it meta provider collection universal_io]
- step_progress_indicator 1.0.1 [flutter]
- syncfusion_flutter_charts 19.4.38 [flutter intl vector_math syncfusion_flutter_core]
- syncfusion_flutter_pdfviewer 19.4.38-beta [flutter vector_math async http uuid syncfusion_flutter_pdfviewer_platform_interface syncfusion_flutter_pdfviewer_web syncfusion_flutter_pdfviewer_macos syncfusion_flutter_core syncfusion_flutter_pdf]
- textfield_tags 1.4.2 [flutter]
- uni_links 0.5.1 [flutter uni_links_platform_interface uni_links_web]
- url_launcher 6.0.17 [flutter meta url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]

transitive dependencies:
- animated_stack_widget 0.0.4 [flutter]
- args 2.3.0
- async 2.8.2 [collection meta]
- cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.1.0
- charcode 1.3.1
- charts_common 0.12.0 [collection intl logging meta vector_math]
- clock 1.1.0
- collection 1.15.0
- convert 3.0.1 [typed_data]
- cross_file 0.3.2 [flutter js meta]
- crypto 3.0.1 [collection typed_data]
- dbus 0.6.6 [args ffi meta xml]
- device_info_plus_linux 2.1.0 [device_info_plus_platform_interface file flutter meta]
- device_info_plus_macos 2.2.0 [device_info_plus_platform_interface flutter]
- device_info_plus_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- device_info_plus_web 2.1.0 [device_info_plus_platform_interface flutter_web_plugins flutter]
- device_info_plus_windows 2.1.0 [device_info_plus_platform_interface ffi flutter win32]
- dio 4.0.4 [http_parser path]
- ffi 1.1.2
- file 6.1.2 [meta path]
- firebase 9.0.2 [http http_parser js]
- firebase_analytics_platform_interface 3.0.3 [firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.0+4 [firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_core_platform_interface 4.2.3 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.5.3 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.1.11 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_in_app_messaging_platform_interface 0.2.0+5 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 3.1.4 [firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 2.2.5 [firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_performance_platform_interface 0.1.0+3 [firebase_core flutter plugin_platform_interface]
- firebase_performance_web 0.1.0+3 [firebase firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins js]
- flutter_blurhash 0.6.0 [flutter meta pedantic]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_local_notifications_linux 0.4.0 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 5.0.0 [flutter plugin_platform_interface]
- flutter_map_marker_popup 2.0.1 [flutter flutter_map latlong2 animated_stack_widget]
- flutter_osm_interface 0.1.10+3 [flutter plugin_platform_interface stream_transform location google_polyline_algorithm dio]
- flutter_plugin_android_lifecycle 2.0.5 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- geocoding_platform_interface 2.0.1 [flutter meta plugin_platform_interface]
- geolocator_android 3.0.1 [flutter geolocator_platform_interface]
- geolocator_apple 2.0.0+2 [flutter geolocator_platform_interface]
- geolocator_platform_interface 3.0.1 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.1 [flutter flutter_web_plugins geolocator_platform_interface]
- google_api_headers 1.1.1 [flutter package_info_plus]
- google_maps_webservice 0.0.20-nullsafety.5 [http meta json_annotation]
- google_polyline_algorithm 3.1.0
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- image_picker_for_web 2.1.4 [flutter flutter_web_plugins image_picker_platform_interface meta]
- image_picker_platform_interface 2.4.1 [flutter http meta plugin_platform_interface cross_file]
- in_app_review_platform_interface 2.0.2 [flutter url_launcher plugin_platform_interface platform]
- js 0.6.3
- json_annotation 4.4.0 [meta]
- linkify 4.1.0
- lists 1.0.1 [meta]
- location_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- location_web 3.1.1 [flutter flutter_web_plugins http_parser js location_platform_interface meta]
- logging 1.0.2
- matcher 0.12.11 [stack_trace]
- meta 1.7.0
- mgrs_dart 2.0.0 [unicode]
- nested 1.0.0 [flutter]
- octo_image 1.0.1 [flutter flutter_blurhash]
- package_info_plus_linux 1.0.3 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.4 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 1.0.4 [package_info_plus_platform_interface ffi flutter win32]
- path 1.8.1
- path_drawing 1.0.0 [vector_math meta path_parsing flutter]
- path_parsing 1.0.0 [vector_math meta]
- path_provider 2.0.8 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.9 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.7 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.4 [ffi flutter meta path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.4 [flutter meta path_provider_platform_interface]
- path_provider_platform_interface 2.0.1 [flutter meta platform plugin_platform_interface]
- path_provider_windows 2.0.4 [ffi flutter meta path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- petitparser 4.4.0 [meta]
- pin_input_text_field 4.1.1 [flutter]
- platform 3.1.0
- plugin_platform_interface 2.0.2 [meta]
- positioned_tap_detector_2 1.0.4 [flutter]
- process 4.2.4 [file path platform]
- proj4dart 2.0.0 [mgrs_dart wkt_parser meta]
- provider 6.0.1 [collection flutter nested]
- quiver 3.0.1+1 [matcher]
- rxdart 0.26.0
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- sqflite 2.0.1 [flutter sqflite_common path]
- sqflite_common 2.0.1+1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- syncfusion_flutter_core 19.4.38 [vector_math flutter]
- syncfusion_flutter_pdf 19.4.38-beta [flutter intl xml syncfusion_flutter_core crypto convert]
- syncfusion_flutter_pdfviewer_macos 19.4.38-beta [flutter syncfusion_flutter_pdfviewer_platform_interface]
- syncfusion_flutter_pdfviewer_platform_interface 19.4.38-beta [flutter plugin_platform_interface]
- syncfusion_flutter_pdfviewer_web 19.4.38-beta [flutter flutter_web_plugins js meta syncfusion_flutter_pdfviewer_platform_interface]
- synchronized 3.0.0
- term_glyph 1.2.0
- timezone 0.8.0 [path]
- transparent_image 2.0.0
- tuple 2.0.0 [quiver]
- typed_data 1.3.0 [collection]
- uni_links_platform_interface 1.0.0 [flutter plugin_platform_interface]
- uni_links_web 0.1.0 [flutter flutter_web_plugins uni_links_platform_interface]
- unicode 0.3.1 [lists]
- universal_io 2.0.4 [collection crypto meta typed_data]
- url_launcher_android 6.0.13 [flutter meta url_launcher_platform_interface]
- url_launcher_ios 6.0.13 [flutter meta url_launcher_platform_interface]
- url_launcher_linux 2.0.2 [flutter]
- url_launcher_macos 2.0.2 [flutter]
- url_launcher_platform_interface 2.0.4 [flutter plugin_platform_interface]
- url_launcher_web 2.0.5 [flutter flutter_web_plugins meta url_launcher_platform_interface]
- url_launcher_windows 2.0.2 [flutter]
- uuid 3.0.5 [crypto]
- vector_math 2.1.0
- win32 2.3.2 [ffi]
- wkt_parser 2.0.0
- xdg_directories 0.2.0 [meta path process]
- xml 5.3.1 [collection meta petitparser]


@priyesh-bit priyesh-bit added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Jan 5, 2022
@priyesh-bit priyesh-bit changed the title 🐛 [firebase_messaging] sound is playing when phone is in silent mode or vibrate mode 🐛 [firebase_messaging] playing sound when phone is in silent mode or vibrate mode Jan 5, 2022
@darshankawar darshankawar added the triage Issue is currently being triaged. label Jan 5, 2022
@darshankawar
Copy link

@priyesh-bit
Are you using a custom sound ? If so, can you check if you are hitting this issue ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 5, 2022
@priyesh-bit
Copy link
Author

@darshankawar Ive already gone through this, but in my sound is coming very well but sound is also coming when phone is in silent mode.

sound : default behaviour is working very well (normal/silent/vibrate)

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 5, 2022
@darshankawar
Copy link

@priyesh-bit
What Android device and OS version you see this behavior on ?
Can you also try upgrading the framework to latest stable (2.8.1) and check ?

@darshankawar darshankawar added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Jan 7, 2022
@priyesh-bit
Copy link
Author

Device info: Nokia C01 Plus - Android 11

@google-oss-bot google-oss-bot added Needs Attention This issue needs maintainer attention. and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jan 7, 2022
@darshankawar
Copy link

Thanks. Keeping it open and labeling it for further inputs.

/cc @russellwheatley

@darshankawar darshankawar added plugin: messaging platform: android Issues / PRs which are specifically for Android. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Jan 10, 2022
@darshankawar
Copy link

@priyesh-bit
Can you take a look at this and see if it helps ?

@darshankawar darshankawar added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label May 27, 2022
@google-oss-bot
Copy link

Hey @priyesh-bit. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label Jun 7, 2022
@google-oss-bot
Copy link

Since there haven't been any recent updates here, I am going to close this issue.

@priyesh-bit if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@darshankawar darshankawar added the resolution: no-response Customer did not respond after some time. label Jun 20, 2022
@darshankawar darshankawar removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 20, 2022
@firebase firebase locked and limited conversation to collaborators Jul 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-by-bot platform: android Issues / PRs which are specifically for Android. plugin: messaging resolution: no-response Customer did not respond after some time. Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants