Reputation: 663
This is my notification function , How to set a custom sound from my assets?
Future<void> _repeatNotification() async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'repeating channel id',
'repeating channel name',
'repeating description',
);
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.periodicallyShow(0, 'Title',
'Body', RepeatInterval.EveryMinute, platformChannelSpecifics);
}
Upvotes: 3
Views: 2044
Reputation: 19
You can play the asset sound through the following property:
sound: const UriAndroidNotificationSound("assets/tunes/pop.mp3"),
Worked 100% correctly:
await flutterLocalNotificationsPlugin.schedule(
id,
"Notification",
'Notification Alert',
dateTime,
NotificationDetails(
android: AndroidNotificationDetails(
"channel.id",
"channel.name",
importance: Importance.max,
priority: Priority.high,
color: primaryColor,
playSound: true,
sound: const UriAndroidNotificationSound("assets/tunes/azan.mp3"),
icon: '@mipmap/ic_launcher'
)
)
);
Upvotes: 1
Reputation: 1214
Custom sounds should be set from the native Android and iOS projects. For Android this will be the raw
folder.
You can play the custom sound by defining its name while instantiating the NotificationDetails
AndroidNotificationDetails(
'repeating channel id',
'repeating channel name',
'repeating description',
sound: 'your_sound_file_name',
);
IOSNotificationDetails(sound: "your_sound_file_name.aiff")
Upvotes: 4