Flutter:很棒的通知从存储中选择声音

问题描述 投票:0回答:1

我正在使用 flutter Awesome 通知,我希望用户可以从其存储中选择自定义声音。有可能做到吗? 这是我的代码来初始化很棒的通知插件。

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,
    )
  ]
);

这是我创建通知的代码

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,
  )
);
flutter localnotification flutter-notification
1个回答
0
投票

根据插件文档 声音只能是资源文件,这意味着它们只能由开发人员预定义,而不能由用户根据需要进行选择。



因此,唯一可能的选择是正如您在此评论中提到的那样,在

res
中加载许多声音并允许用户从中进行选择。

© www.soinside.com 2019 - 2024. All rights reserved.