0

I want to add custom sound to my push notification and I have tried a lot of things but I could not get it to work

I tired this this and this but it did not work and I do not want to use local notification because I want it to work on both IOS and android and I want it to work in the background

this is my code

 void sendPushMessage(String token, String body, String title) async {
    await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
        headers: <String, String>{
          'Content-Type': 'application/json',
          'Authorization':
              'private key'
        },
        body: jsonEncode(<String, dynamic>{
          'Priority': 'high',
          'data': <String, dynamic>{
            'click_action': 'FLUTTER_NOTIFICATION_CLICK',
            'status': 'done',
            'title': title,
            "sound": "test.wav",
          },
          'notification': <String, dynamic>{
            'title': title,
            'body': body,
            "sound": "test.wav",
            'android_channel_id': ''
          },
          'to': token
        }));
  }

and I added the test.wav file to res/raw/ path

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

Hey did you try to reformat the sound when showing it in IOS the format could be like this 'notification_sound.aiff',",

const androidPlatformChannel = AndroidNotificationDetails(
  'ANDROID_CHANNEL_ID',
  'Name',
  'Description',
  color: Color.fromARGB(255, 0, 0, 0),
  importance: Importance.max,
  sound: RawResourceAndroidNotificationSound('notification_sound'),
  playSound: true,
  priority: Priority.high,
  showWhen: false,
);

const iOSPlatformChannel = IOSNotificationDetails(
  sound: 'notification_sound.aiff',
  presentAlert: true,
  presentBadge: true,
  presentSound: true,
);

const platformChannel = NotificationDetails(
  android: androidPlatformChannel,
  iOS: iOSPlatformChannel,
);
Dewa Prabawa
  • 497
  • 2
  • 11