Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom sound doesn't work on android #563

Closed
JakaboosD opened this issue Apr 6, 2020 · 3 comments
Closed

custom sound doesn't work on android #563

JakaboosD opened this issue Apr 6, 2020 · 3 comments

Comments

@JakaboosD
Copy link

JakaboosD commented Apr 6, 2020

I'm trying to play my own custom sound for my notifications on android. But on my android emulator, it just plays the default sound and on my personal device, it doesn't even make a sound (both run android 9).

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

@MaikuB
Copy link
Owner

MaikuB commented Apr 6, 2020

Note that the sound is tied to the notification channel, which is created the first time you try to show a notification against a particular channel ID. The settings passed in will persist so won't change even if you changed the settings around the sound but use the same channel ID. So if you went through using the default sound (which is what happens by default when you don't specify anything) to specifying a custom sound, you'll need to uninstall and reinstall the app

@MaikuB
Copy link
Owner

MaikuB commented Apr 6, 2020

Regarding the sound not playing on your phone, you'll need to check the settings on your phone. The volume level is separate from getting notification sounds

@JakaboosD
Copy link
Author

Thanks! That did the trick! On my personal phone it was the same problem. I had just been updating the app. I uninstalled and reinstalled the app and now it plays my custom sound!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants