我从我的服务器使用 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/