【发布时间】:2019-12-13 14:34:20
【问题描述】:
如何在flutter_local_notification中添加自定义mp3声音,有添加自定义铃声的功能,可惜没有文档或示例。
【问题讨论】:
标签: flutter dart notifications
如何在flutter_local_notification中添加自定义mp3声音,有添加自定义铃声的功能,可惜没有文档或示例。
【问题讨论】:
标签: flutter dart notifications
在 android 项目中添加 raw 文件夹: android>app>src>main>res> 新的 Android 资源目录 > 选择 Raw > 在此处添加你的声音
Result Folder :
- android
- app
- src
- main
- res
- raw
lawgo_sound_notification.mp3
图片在这里:[1]:https://i.stack.imgur.com/EHquv.png
实现您的本地通知代码:
var androidPlatformChannel = new AndroidNotificationDetails(
"your_channel_id", "name", "desc_channel",
sound: RawResourceAndroidNotificationSound('lawgo_sound_notification'),
playSound: true,
importance: Importance.Max,
priority: Priority.High);
添加 onResume、OnLaunch 支持,当应用在后台通知负载上运行时应设置为:
{ "notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification",
"android_channel_id": "your_channel_id"
},
"data" : {
"body" : "Body of Your Notification in Data",
"title": "Title of Your Notification in Title",
"click_action": "FLUTTER_NOTIFICATION_CLICK",
}
}
**important should add "android_channel_id": "default_notification_channel_id"**
【讨论】:
在文档中,有很多关于如何处理自定义声音的信息。您需要在android文件夹中配置资源并使用config设置声音。此外,您可能需要检查。如何。使用通知渠道。在源代码中,有一个示例文件夹,其中有演示:
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'your other channel id',
'your other channel name',
'your other channel description',
icon: 'secondary_icon',
sound: 'slow_spring_board',
largeIcon: 'sample_large_icon',
largeIconBitmapSource: BitmapSource.Drawable,
vibrationPattern: vibrationPattern,
enableLights: true,
color: const Color.fromARGB(255, 255, 0, 0),
ledColor: const Color.fromARGB(255, 255, 0, 0),
ledOnMs: 1000,
ledOffMs: 500);
【讨论】: