Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add mp3 sound in flutter_local_notifications

How to add custom mp3 sound in flutter_local_notification, there is a feature of adding custom ringtone but unfortunately no documentation or examples.

like image 937
SOUGAT RIYADH Avatar asked Dec 13 '19 14:12

SOUGAT RIYADH


1 Answers

Add raw folder in android project : android>app>src>main>res> New Android Resource Directory > Select Raw > add your sound here

Result Folder :
- android
- app
  - src 
    - main
      - res
        - raw
            lawgo_sound_notification.mp3

image here : [1]: https://i.stack.imgur.com/EHquv.png

implement your local notification code:

var androidPlatformChannel = new AndroidNotificationDetails(
    "your_channel_id", "name", "desc_channel",
    sound: RawResourceAndroidNotificationSound('lawgo_sound_notification'),
    playSound: true,
    importance: Importance.Max,
    priority: Priority.High);

add onResume, OnLaunch support, when apps run on background notification payload should be setup to this:

{ "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"**
like image 143
Muhamamd Kharis Azhar NS Avatar answered Nov 03 '22 01:11

Muhamamd Kharis Azhar NS