如何在flutter_local_notification中添加自定义mp3声音,具有添加自定义铃声的功能,但不幸的是,没有文档或示例。
答案 0 :(得分:4)
在android项目中添加原始文件夹: android> app> src> main> res>新的Android资源目录>选择原始>在此处添加声音
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"**
答案 1 :(得分:1)
在文档中,有许多有关如何处理自定义声音的信息。您需要在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);
您可以在https://github.com/MaikuB/flutter_local_notifications/blob/master/example/lib/main.dart
上查看完整的示例