Flutter:本地通知自定义声音不起作用 [英] Flutter: local notifications custom sound doesn't work
问题描述
我正在尝试为自己的通知播放自己的自定义声音.但是在我的Android模拟器上,它只播放默认声音,而在我自己的设备上,它甚至不发出声音.我尝试了此,但是它没有帮助我.
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);
我没有任何错误.我的文件位于android/app/src/main/res/raw/my_sound.mp3
I don't get any errors. My file is in android/app/src/main/res/raw/my_sound.mp3
推荐答案
简单修复!您必须完全卸载并重新安装该应用程序,而不仅仅是对其进行更新.首次安装时的通知设置将保留,因此,如果将其一次设置为默认声音,则在不更改频道ID的情况下将保留.更多信息此处
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
这篇关于Flutter:本地通知自定义声音不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!