Звук уведомления не работает во флаттере flutter_local_notifications

      Future scheduleAlarmWithSound(Task task) async {
    final exists = await _checkIfAlreadyScheduled(task.id);
    if (exists) return;

    var scheduleNotificationDateTime =
        DateTime.fromMillisecondsSinceEpoch(task.endTime);
    const AndroidNotificationDetails androidPlatformChannelSpecifics =
        AndroidNotificationDetails('v1', 'Todo', 'Reminder',
            icon: 'icon',
            importance: Importance.max,
            priority: Priority.high,
            largeIcon: DrawableResourceAndroidBitmap('icon'),
            sound: RawResourceAndroidNotificationSound('annoyingalarm'),
            playSound: true,
            showWhen: true);
    const NotificationDetails platformChannelSpecifics =
        NotificationDetails(android: androidPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.schedule(
        task.id,
        task.task,
        'Time\'s up!\n Did you completed the task?\nIf not better luck next time.',
        scheduleNotificationDateTime,
        platformChannelSpecifics);
    print("Alarm scheduled with sound");
  }

  Future scheduleAlarmWithoutSound(Task task) async {
    final exists = await _checkIfAlreadyScheduled(task.id);
    if (exists) return;

    var scheduleNotificationDateTime =
        DateTime.fromMillisecondsSinceEpoch(task.endTime);
    const AndroidNotificationDetails androidPlatformChannelSpecifics =
        AndroidNotificationDetails('v1', 'Todo', 'Reminder',
            icon: 'icon',
            importance: Importance.max,
            priority: Priority.high,
            largeIcon: DrawableResourceAndroidBitmap('icon'),
            playSound: false,
            showWhen: true);
    const NotificationDetails platformChannelSpecifics =
        NotificationDetails(android: androidPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.schedule(
        task.id,
        task.task,
        'Time\'s up! Did you completed the task?',
        scheduleNotificationDateTime,
        platformChannelSpecifics);
    print("Alarm scheduled without sound");
  }

Прежде всего, позвольте мне объяснить свою программу. Это приложение-напоминание. Если мы нажмем кнопку «Напомнить мне», будет установлено уведомление со звуковым сигналом, иначе будет установлено уведомление без звукового сигнала. Также есть возможность изменить это решение в будущем. Проблема в том, что при установке напоминания звуковым сигналом будильника звук не воспроизводится. Но звук проигрывается, если нет функции установки будильника без звука.

0 ответов