使用flutter_local_notification包显示预定通知,通过使用自定义声音,但我希望用户从列表中选择铃声,在iOS上它工作正常,但在Android端,如果选择了新铃声,它将播放旧铃声。
addnotification(DateTime time, int id, String? ringtone) {
log('$ringtone', name: 'notification ringtone');
tzData.initializeTimeZones();
log(tz.local.toString(), name: 'time zone');
final scheduleTime = tz.TZDateTime.from(time, tz.local);
NotificationDetails notificationDetails = NotificationDetails(
android: AndroidNotificationDetails(
'mychannel2',
'alarm',
// const UriAndroidNotificationSound(
// 'assets/ringtones/alarm.mp3'), //
sound: RawResourceAndroidNotificationSound('$ringtone'),
importance: Importance.max,
priority: Priority.high,
// autoCancel: false,
// timeoutAfter: 10000,
// vibrationPattern: Int64List(5),
// category: AndroidNotificationCategory.alarm,
enableLights: true,
fullScreenIntent: true,
enableVibration: true,
audioAttributesUsage: AudioAttributesUsage.alarm,
visibility: NotificationVisibility.public,
playSound: true,
),
iOS: DarwinNotificationDetails(
presentSound: true, sound: '$ringtone.wav'));
_localNotificationsPlugin.zonedSchedule(id, 'Morning Alarm',
'wake up the alarm is ringing...', scheduleTime, notificationDetails,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true,
matchDateTimeComponents: DateTimeComponents.time);
// _localNotificationsPlugin.show(id, 'alarm', 'alarm', notificationDetails);
}
1条答案
按热度按时间myzjeezk1#
根据其文件:
对于Android 8.0+,声音和振动与通知通道相关联,并且只能在首次创建时进行配置。显示/计划通知时,将创建一个具有指定ID的通道(如果该通道尚不存在)。如果另一个通知指定了相同的通道ID,但尝试指定另一个声音或振动模式,则不会发生任何操作。
您可以尝试为每个具有不同声音的通知创建新通道。
更多信息请访问https://pub.dev/packages/flutter_local_notifications#-android-setup