2

I looked up in the net, it was suggested to set the additionalFlags option of AndroidNotificationDetails to have a value of 4.

This is what I did

AndroidNotificationDetails(
      'notif',
      'notif',
      'Notification',
      icon: '@mipmap/launcher',
      priority: Priority.high,
      sound: RawResourceAndroidNotificationSound('notif'),
      largeIcon: DrawableResourceAndroidBitmap('@mipmap/launcher'),
      additionalFlags: Int32List.fromList(<int>[4]),
      importance: Importance.max,
      playSound: true,
    );

But the moment I swipe down to see the list of notifications, the sound stops playing. I want the sound to keep playing, unless and until I tap on that particular notification (and not merely swipe down to see the list of notifications)?

godwa_rao
  • 187
  • 1
  • 10

1 Answers1

2

You can persist the sound (or in this example an alarm) by using a insistentFlag and the androidAllowWhileIdle flag.
The below example uses Flutter local Notifications v.12

static Future<void> showFullScreenNotification(
      Alarm alarm, tz.TZDateTime date) async {

    const int insistentFlag = 4;

    final Int64List vibrationPattern = Int64List(4);
    vibrationPattern[0] = 0;
    vibrationPattern[1] = 4000;
    vibrationPattern[2] = 4000;
    vibrationPattern[3] = 4000;

    AndroidNotificationDetails androidPlatformChannelSpecifics =
    AndroidNotificationDetails(
      alarm.id.toString(),
      'scheduled_alarm_channel',
      channelDescription: 'scheduled_alarm',
      priority: Priority.high,
      importance: Importance.high,
      additionalFlags: Int32List.fromList(<int>[insistentFlag]),
      playSound: true,
      audioAttributesUsage: AudioAttributesUsage.alarm,
      vibrationPattern: vibrationPattern,
    );

    NotificationDetails details =
    NotificationDetails(android: androidPlatformChannelSpecifics);

    await flutterLocalNotificationsPlugin.zonedSchedule(
      ...
      date,
      androidAllowWhileIdle: true,
      ...
    );
  }
kiwi
  • 53
  • 5