flutterpush-notificationawesome-notifications

How to customize notification sound in Awesome Notification


I am trying to create an alarming notification with my alarm.wav sound. I listened to some tutorials and found that I need to put my sounds in the android/app/src/main/res/raw. when trying to push the notification using awesome_notifications package, it just plays the default device notification sound. Can someone see if I am doing something wrong because no error is poping up.

AwesomeNotifications().createNotification(
        content: NotificationContent(
            id: id,
            actionType: actionType,
            title: title,
            category: NotificationCategory.Alarm,
            criticalAlert: true,
            wakeUpScreen: true,
            channelKey: 'high_importance_channel',
            body: body,
            customSound: "resource://raw/alarm",
            // payload: json.decode(payLoad),
            ),
     );

EDIT

I also tried to pass the path as my soundSource argument but gave me this error:

[Awesome Notifications](12613): Audio media is not valid (NotificationChannelModel:58)

code:

await AwesomeNotifications().initialize(null, [
      NotificationChannel(
        channelKey: 'high_importance_channel',
        channelName: 'alert_channel',
        channelDescription: 'Alert user from certain health issues',
        playSound: true,
        soundSource: "resource://raw/alarm",
      )
    ]);

Solution

  • i had the exact same issue .

    try renaming the file from alarm.wav to res_alarm.wav .

    this was mentioned in the documentation under Media Source Types Link

    after that do a flutter clean & flutter pub get you should be good to go

    if it still doesn't work try other media extensions caf,mp3 or etc.

    await AwesomeNotifications().initialize(null, [
    NotificationChannel(
        importance: NotificationImportance.High,
        defaultPrivacy: NotificationPrivacy.Public,
        defaultColor: Colors.transparent,
        vibrationPattern: lowVibrationPattern,
        locked: true,
        soundSource: 'resource://raw/res_water',
        enableVibration: true,
        criticalAlerts: true,
        playSound: true,
        channelGroupKey: "Water_channel_group",
        channelKey: "Water",
        channelName: " Water Remind",
        channelDescription: "Water sound"),