Flutter: local notifications custom sound doesn't work

允我心安 提交于 2021-02-10 06:57:31

问题


I'm trying to play my own custom sound for my notifications. But on my android emulator, it just plays the default sound and on my own device, it doesn't even make a sound. I tried this but it didn't help me.


FlutterLocalNotificationsPlugin _notifications = FlutterLocalNotificationsPlugin();

var initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(initializationSettingsAndroid, initializationSettingsIOS);
await _notifications.initialize(initializationSettings);
var androidPlatformChannelSpecifics = AndroidNotificationDetails('test_channel', 'test', '', playSound: true, sound: RawResourceAndroidNotificationSound('my_sound'));
var iOSPlatformChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await _notifications.show(0, 'test', 'this is a test', platformChannelSpecifics);

I don't get any errors. My file is in android/app/src/main/res/raw/my_sound.mp3


回答1:


Simple fix! You have to uninstall and reinstall the app completely instead of just updating it. The notification settings from your first install will persist, so if it was once set to default sound, that will persist if you don't change the channel id. More info here



来源:https://stackoverflow.com/questions/61046666/flutter-local-notifications-custom-sound-doesnt-work

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