android - 带有数据负载的 Firebase 通知声音

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

我从我的服务器使用 Firebase API 发送通知,我使用数据:而不是通知:...当我使用通知时,声音有效。我只是设置了 sound = default,它会在后台收到通知时播放。

当我使用 DATA 时,我仍然收到消息,但是当我设置 sound = default 时没有声音播放。我必须将我的声音作为 mp3 加载到项目中吗?或者我必须在我的 FiremaseMessagingService.java 文件 onReceive 中做些什么?

似乎当我另外使用通知时。使用 ONY 通知,数据未通过

最佳答案

sound 参数是 Notification payloads 的预定义参数,其中通知消息是(根据 docs ):

FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.

换句话说,系统是自动处理的。因此,您看到的行为是预期的行为。

使用 Data payload 时(来自上面的相同文档):

Client app is responsible for processing data messages. Data messages have only custom key-value pairs.

您必须在 onMessageReceived() 中实现如何处理负载中的详细信息(这是假设您的应用程序在前台,您仍然需要了解如何至 handle the messages,具体取决于您的应用程序状态)。这包括您包含的 sound 参数。

关于android - 带有数据负载的 Firebase 通知声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40595309/

相关文章:

android - 应用程序 Logo 一半在 ActionBar 中,一半在 mainActivty 屏幕上

android - 发布 gradle artifact whitout source

android - 将 SQLite 数据库同步到 App Engine 数据存储区?

ruby - 在 firebase firestore 中超时读写数据

iOS - Firebase 返回 null 但存在数据字段

iphone - 如何知道 Pubnub 中的退订 channel 请求是否成功?

android - 如何在 Android 和 IOS 中创建基本的 Google Glass 应用程序

java - 如何知道 firebase 中的值是增加还是减少?

cordova - 如何在 Cordova 移动中配置 amazon SNS 以接收推送通知

php - iPhone 中的推送通知问题