Firebase push notification with custom sound (Flutter)

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!