在android中发送来自firebase的通知时没有通知声音 [英] No notification sound when sending notification from firebase in android
问题描述
我从Firebase发送推送通知到我的Android应用程序。但是当我的应用程序在后台firebase onMessageReceived方法不被调用,而是firebase发送通知系统显示系统托盘中的通知。
通知出现在系统托盘中,但是没有通知声音,即使我在系统设置中允许我的应用程序通知声音。
当我从firebase收到通知时,我可以播放通知声音。
这就是我发送从firebase通知我的应用程序[link below]。
$ b
的通知有一个健全的关键。
从官方文件中它的用途是:
lockquote
表示设备收到通知时播放的声音。
支持
应用程序中捆绑的声音资源的默认值或文件名。声音文件必须位于/ res / raw /。
例如:
<$
to:bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ...,
通知:{
body:
title:Portugal vs. Denmark,
icon:myicon,
sound:mySound
}
如果你想使用设备的默认声音,你应该使用:<$ c
请参阅以下链接了解有效载荷中所有可能的键:
https://firebase.google.com/docs/cloud -messaging / http-server-ref#notification-payload-support
对于那些不知道firebase会在应用程序处于后台。在这种情况下,不会调用onMessageReceived函数。
lockquote
当您的应用程序在后台时,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 [Link below].
Add firebase in your android application
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.
这篇关于在android中发送来自firebase的通知时没有通知声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!