1 year ago

#324884

test-img

Shubham K

How can I play different sounds for notifications in flutter using flutter_local_notification

I have 2 different kinds of notification messages. I want to understand, how can I play different sounds for notifications.

I tried by changing the sound string in AndroidNotificationDetails, but it plays same sound for both types.

static void displayNotification(RemoteMessage message) async { 
    try { 
        final id =   DateTime.now().millisecondsSinceEpoch ~/ 1000;  
        await _notificationsPlugin.show(
            id,
            message.notification.title,
            message.notification.body,
            NotificationDetails(
                android: AndroidNotificationDetails(
                "default_channel",
                "Default channel Notifications",
                importance: Importance.max,
                priority: Priority.high,
                playSound: true,
                sound: RawResourceAndroidNotificationSound( message.data['type'] == "1" ?  'notification_one' : 'notification_two'),
          ),
        ),
        payload: message.payload,
      );

    } on Exception catch (e) {
          print(e);
    }
}

firebase

flutter

firebase-cloud-messaging

firebase-notifications

flutter-local-notification

0 Answers

Your Answer

Accepted video resources