Firebase push notification with custom sound (Flut

2019-05-24 09:23发布

问题:

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 can be done by putting "sound: blabla.mp3" inside the payload, but how do i define the sound inside dart page?

回答1:

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

widget._firebaseMessaging.configure(
  onMessage: (Map<String, dynamic> message) async {
    print('on message $message');



    AudioCache player = new AudioCache();
    const alarmAudioPath = "sounds/notification.mp3";
    player.play(alarmAudioPath);
  },
  onResume: (Map<String, dynamic> message) async {
    print('on resume $message');
  },
  onLaunch: (Map<String, dynamic> message) async {
    print('on launch $message');
  },
);

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



标签: dart flutter