从android中的firebase发送通知时没有通知声音 [英] No notification sound when sending notification from firebase in android

查看:47
本文介绍了从android中的firebase发送通知时没有通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 firebase 向我的 Android 应用程序发送推送通知.但是当我的应用程序在后台时,firebase onMessageReceived 方法不会被调用,而是 firebase 向系统发送通知以在系统托盘中显示通知.通知出现在系统托盘中,但没有通知声音,即使我在系统设置中允许我的应用程序发出通知声音.

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.

当收到来自 firebase 的通知时,我可以做些什么来播放通知声音.

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

这就是我从 firebase 向我的应用发送通知的方式 Blogpost链接.

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

如何在您的 Android 应用程序中添加 firebase

推荐答案

在通知的通知载荷中有一个声音键.

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

从官方文档看它的用途是:

From the official documentation its use is:

表示设备收到通知时要播放的声音.支持默认或捆绑的声音资源的文件名应用程序.声音文件必须位于/res/raw/.

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/.

例如:

{
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",

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

如果你想使用设备的默认声音,你应该使用:"sound": "default".

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

请参阅此链接以获取有效负载中所有可能的键:https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

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

对于那些不知道 Firebase 在应用处于后台时以不同方式处理通知的用户.在这种情况下,不会调用 onMessageReceived 函数.

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.

当您的应用处于后台时,Android 会发送通知消息到系统托盘.用户点击通知会打开默认情况下应用启动器.这包括同时包含通知和数据有效载荷.在这些情况下,通知是传送到设备的系统托盘,并且数据有效负载是在您的启动器 Activity 的意图的附加内容中交付.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆