颤振的本地通知自定义声音不起作用(路径问题) [英] Flutter local notification custom sound doesn't work (path issue)
问题描述
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails(
"$id",
not.columnValue + not.deveui,
not.columnValue + not.deveui,
sound: "@raw/alarm",
importance: Importance.Max,
priority: Priority.High);
实际上,它仍然会使用默认的系统声音.
如果放入@raw/alarm.mp3
,则会出现以下异常:Unhandled Exception: PlatformException(INVALID_SOUND, The resource %s could not be found. Please make sure it has been added as a raw resource to your Android head project., null)
Actually it still sounds with the default system sound.
If I put @raw/alarm.mp3
, I got the following exception: Unhandled Exception: PlatformException(INVALID_SOUND, The resource %s could not be found. Please make sure it has been added as a raw resource to your Android head project., null)
注意:声音:RawResourceAndroidNotificationSound('alarm'),已解决
note : sound: RawResourceAndroidNotificationSound('alarm'), solved
推荐答案
您不需要将'@ raw/'放置到路径中,插件已经在从中获取声音(根据插件来源:FlutterLocalNotificationsPlugin.java函数retrieveSoundResourceUri ),请删除它.
You don't need to put '@raw/' to path, plugin is already taking sounds from it (according to plugin source: FlutterLocalNotificationsPlugin.java function retrieveSoundResourceUri) so remove it.
还请检查声音文件是否包含在内部版本中.通过在原始文件夹中创建具有以下内容的keep.xml
also check that sound file is included in build, ex. by creating keep.xml in raw folder with following content
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*,@raw/alarm" />
可能有帮助
这篇关于颤振的本地通知自定义声音不起作用(路径问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!