具有自定义声音的Firebase推送通知(Flutter) [英] Firebase push notification with custom sound (Flutter)

查看:612
本文介绍了具有自定义声音的Firebase推送通知(Flutter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Firebase消息传递云为我的应用推送通知。我正在尝试为推送通知发出自定义通知声音。我相信可以通过在有效负载中放入 sound:blabla.mp3来实现,但是我如何在dart页面中定义声音?

I'm currently using firebase messaging cloud to push notification for my app. I'm trying to make a custom notification sound for the push notification. I believe that it can be done by putting "sound: blabla.mp3" inside the payload, but how do i define the sound inside dart page?

推荐答案

要为两个Android都创建自定义通知声音,您需要为您的应用程序预先定义一个通知频道。我使用了 Flutter Local Notifications 插件来执行此操作。在此处,您可以为Android通知频道指定参数,例如

To create a custom notification sound for both Android you will need to predefine a Notification Channel for your app. I used Flutter Local Notifications plugin to do this. In there, you can specify the parameters for your Android Notification Channel such as

var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'您的其他频道ID ',
'您的其他频道名称',
'您的其他频道说明',
声音:RawResourceAndroidNotificationSound('slow_spring_board');

注意:slow_spring_board.mp3存储在您的 android\app\src\main\res\raw 部分中app。调用 RawResourceAndroidNotificationSound()

Note: slow_spring_board.mp3 is stored in the android\app\src\main\res\raw section of your app. Do not include the file extension when calling RawResourceAndroidNotificationSound()

时不包含文件扩展名适用于iOS设备(不支持mp3)。完成所有操作后,您就可以开始处理云消息传递部分了,在该部分中,您必须引用通知频道ID和声音文件,建议您包含音频文件该代码中的扩展名。

There are other steps required to get it setup for iOS devices (mp3 are not supported). Once this is all done, you can begin working on your cloud messaging portion, in there you'll have to reference the notification channel id, and the sound file. I recommend including the audio file extension in that code.

这篇关于具有自定义声音的Firebase推送通知(Flutter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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