问题
I want setting up a custom sound for my local notification in the Android side.
I created a raw folder in the res folder of Android project.
This is the part of my code which I put my alarm.mp3 file path in the notification.
var androidPlatformChannelSpecifics =
new AndroidNotificationDetails(
"$id",
not.columnValue + not.deveui,
not.columnValue + not.deveui,
sound: "@raw/alarm",
importance: Importance.Max,
priority: Priority.High);
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)
回答1:
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.
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" />
that might help
来源:https://stackoverflow.com/questions/59783904/flutter-local-notification-custom-sound-doesnt-work-path-issue