android - 从android中的firebase发送通知时没有通知声音

标签 android push-notification notifications firebase firebase-cloud-messaging

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

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

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

How to Add firebase in your Android Application

最佳答案

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

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

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"

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

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

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 - 从android中的firebase发送通知时没有通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959588/

相关文章:

android - 如何从 Ubuntu 12.04(64 位)中删除所有 Android 工具(ADB 和 fastboot)以及 SDK

ios - 如何防止 ios 中的本地通知重复?

amazon-web-services - 我需要根据 Amazon Athena 中查询返回的结果创建警报

Android通知小图标在通知抽屉中放大

android - 如何更改Android Material TextInputLayout组件的非 Activity 边框笔触颜色

java - AlertDialog 和软键盘

android - 掩蔽(裁剪)帧中的图像

node.js - Flutter 推送通知仅在应用程序处于后台时才有效

ios - 使用适用于 IOS 的 Parse SDK 进行推送未在设备中交付

android - 规范的注册 ID 和消息 ID 格式