Firebase push notification with custom sound (Flutter)

后端 未结 3 1666
失恋的感觉
失恋的感觉 2021-01-12 05:18

I\'m currently using firebase messaging cloud to push notification for my app. I\'m trying to make a custom notification sound for the push notification. I believe that it c

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 06:01

    you can do this simply by calling the sound and playing it in the firebase configure method.

    widget._firebaseMessaging.configure(
      onMessage: (Map message) async {
        print('on message $message');
    
    
    
        AudioCache player = new AudioCache();
        const alarmAudioPath = "sounds/notification.mp3";
        player.play(alarmAudioPath);
      },
      onResume: (Map message) async {
        print('on resume $message');
      },
      onLaunch: (Map message) async {
        print('on launch $message');
      },
    );
    

    this wouldnt be effective as the file wouldnt be played if the app is in the background

提交回复
热议问题