No notification sound when sending notification from firebase in android

前端 未结 9 1726
迷失自我
迷失自我 2020-12-01 01:00

I am sending push notification from firebase to my Android Application. but when my app is in background firebase onMessageReceived method is not called instead firebase sen

9条回答
  •  感情败类
    2020-12-01 01:51

    In the notification payload of the notification there is a sound key.

    From the official documentation its use is:

    Indicates a sound to play when the device receives a notification. Supports default or the filename of a sound resource bundled in the app. Sound files must reside in /res/raw/.

    Eg:

    {
        "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    
        "notification" : {
          "body" : "great match!",
          "title" : "Portugal vs. Denmark",
          "icon" : "myicon",
          "sound" : "mySound"
        }
      }
    

    If you want to use default sound of the device, you should use: "sound": "default".

    See this link for all possible keys in the payloads: https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

    For those who don't know firebase handles notifications differently when the app is in background. In this case the onMessageReceived function is not called.

    When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload. In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

提交回复
热议问题