Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No notification sound when sending notification from firebase in android

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 send notification to system for showing notification in system tray. notification appears in system tray but no sound for notification even i have allowed notification sound for my app in system settings.

what I can do to play notification sound when notification received from firebase.

This is how I am sending notification from firebase to my app Blogpost link.

How to Add firebase in your Android Application

like image 693
Developine Avatar asked Jun 22 '16 05:06

Developine


People also ask

How do I get Firebase notifications on Android?

Step 1, Go to the Firebase console. Under Engage, go to Cloud Messaging. We can use this tool to send out notifications to a specific group, device, or topic. Click on “Send your first message” and enter a title and text for the notification.

Can Firebase send push notification?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.


2 Answers

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.

like image 131
Isj Avatar answered Sep 20 '22 21:09

Isj


adavaced options select advanced options when Write a message, and choose sound activated choose activated

this is My solution

like image 24
KongJing Avatar answered Sep 19 '22 21:09

KongJing