title: FCM custom sound when app in background flutter
body: <p>I am trying to play a custom sound when a push notification is received on my flutter app. However it only works when app is opened. How do I ensure users get to hear the sound when the app is closed or in background.</p>
  <pre><code>class PushNotificationService{
    final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
    Future initialize(context) async{
      _firebaseMessaging.configure(
        onMessage: (Map&lt;String, dynamic&gt; message) async {
          print(&quot;onMessage: $message&quot;);
          fetchRideInfo(message['data']['orderId'], context);
        },
        onLaunch: (Map&lt;String, dynamic&gt; message) async {
          print(&quot;onLaunch: $message&quot;);
          fetchRideInfo(message['data']['orderId'], context);
        },
        onResume: (Map&lt;String, dynamic&gt; message) async {
          print(&quot;onResume: $message&quot;);
          fetchRideInfo(message['data']['orderId'], context);
        },
      );
    }
    Future&lt;String&gt; getToken() async{
      print(&quot;fetching token&quot;);
      token = await _firebaseMessaging.getToken();
      print('token got as: $token');
  
    }
  
    void fetchRideInfo(orderId, context) {
      print(&quot;fetching info&quot;);
      showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) =&gt;
            CustomProgressDialog(status:'Fetching details',),);
        assetsAudioPlayer.open(
        Audio('sounds/alert.mp3'),
      );
      assetsAudioPlayer.play();
    }
  
  
  
  
  }
  </code></pre>
  <p><strong>Notification Body</strong></p>
  <pre><code>{
      &quot;notification&quot;: {
      &quot;body&quot;: &quot;this is a body&quot;,
      &quot;title&quot;: &quot;this is a title&quot;
       }, 
      &quot;data&quot;: {
      &quot;click_action&quot;:&quot;FLUTTER_NOTIFICATION_CLICK&quot;, 
      &quot;type&quot;: &quot;normal&quot;,
      &quot;id&quot;: &quot;1&quot;, 
      &quot;ride_id&quot;: &quot;-MKp1WBP8G2kTgJBqwyl&quot;,
      &quot;status&quot;: &quot;done&quot;},
      &quot;to&quot;:&quot;dv9Yq4qHSVubIohoM8niDX:APA91bGJgQkP7Ir867vyo9oT1CeXbWPKP6xMSDUgwu3242W9odgr4vn5qIIgPmY2LQyPNjL8Pwl8GcRY4TbucxVcCBOM0eBZDHnfhh0E0qYvhdWc_0Yd1oBT_Vh1sA0q-haqXQ3KXib5&quot;
  
       }
  </code></pre>