2

I am using flutter awesome notification and I want user can choose custom sound from their storage. Is it possible to make it? Here is my code to initialize the awesome notification plugin.

AwesomeNotifications().initialize(
  'resource://drawable/logo',
  [
    NotificationChannel(
      channelKey: 'alarm_notification',
      channelName: 'alarm_notification',
      channelDescription: 'Notification channel for alarm',
      defaultColor: Color(0xFFFFDA2B),
      ledColor: Colors.white,
      vibrationPattern: highVibrationPattern,
      soundSource: 'resource://raw/slow_spring_board',
      importance: NotificationImportance.Max,
    )
  ]
);

and this is my acode to create notification

AwesomeNotifications().createNotification(
  content: NotificationContent(
    id: alarmId,
    channelKey: 'alarm_notification',
    title: alarmTitle,
    body: alarmBody,
    displayOnBackground: true,
    displayOnForeground: true,
    customSound: "string",
  ),
  schedule: NotificationCalendar(
    hour: alarmTime.hour,
    minute: alarmTime.minute,
    second: 0,
    millisecond: 0,
    timeZone: "Asia/Jakarta",
    repeats: true,
  )
);
adhiskara
  • 81
  • 7
  • Did you manage to get that to work? I can't even get it to work with static customSound. I tried in the initialize with soundSource: 'resource://raw/zedd' and also in the createNotification with customSound: 'asset://assets/audio/zedd.mp3', I get no errors. it just ignores my custom sound :( – J-L Mar 09 '23 at 14:59
  • 1
    @J-L in the end I didn't use the custom sound selectable from storage. I made a dropdown of the sound options that I provide. on AwesomeNotifications initialization I create multiple NotificationChannels with different soundSources. make sure you save the audio file in /android/app/src/main/res/raw/your_file.mp3. and in your raw folder create a keep.xml file which includes your audio files. then i also don't add customSound on NotificationContent – adhiskara Mar 10 '23 at 02:31
  • Thanks for the info about the keep.xml I had no idea about that file. Unfortunately still doesn't work for me .. did you have to add any special permission in the AndroidManifest? for now I have : – J-L Mar 10 '23 at 21:03
  • ok got it to work now.. I had to completely remove the app from the phone .. before running , I think the channels for the notifications were messed up from testing so much .. – J-L Mar 10 '23 at 21:30

0 Answers0