问题
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