Steffaan / cordova-plugin-local-notifications

Cordova Local Notifications Plugin
Apache License 2.0
31 stars 38 forks source link

Sound doesn't work on Android Oreo / Pie #25

Closed hendaoui closed 4 years ago

hendaoui commented 5 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Sound doesn't work on Android Oreo / Pie

Your Environment

Expected Behavior

Playing custom sound when a notification is fired

Actual Behavior

If the properties "channel" or "every" is set, the notification will never appear otherwise, everything works well except the sound.

Context

cordova.plugins.notification.local.schedule({
  title: 'Notification',
  channel: 'customChannel',
  text: 'Notification',
  led: {color: '#FFFFFF', on: 500, off: 500},
  foreground: true,
  priority: 2,
  icon: 'res://icon.png',
  smallIcon: 'res://icon.png',
  sound: "file://assets/audio/sound.mp3",
  trigger: {
    at: new Date(),
    every: 'minute'
  },
});
nijakobius commented 4 years ago

I can second that sound does not work on current Android versions :(

narlei commented 4 years ago

There is any way to play notification sound?

misterti commented 4 years ago

I can confirm the sound IS working on android 9. You have to change the channel name each time you change something in the options passed to schedule, or you have to uninstall the app for changes to take effect. What i tested:

rafaellop commented 4 years ago

I've migrated my app to this plugin instead of the original from Katzer and I'm suffering this too. No sound at all. I don't use own channels or own sound and fallback these to the default, but no sound or vibration is activated. Anything new regarding this @Steffaan ?

misterti commented 4 years ago

You can't fall back to the default, once you schedule with a channel name (or without, which will use the default from the module), this channel is burned to android settings for your app, you can't change anything for this channel anymore, only user can, through Android UI Notifications for your app. You can only uninstall the app or remove the channel through same user settings.

Consider scenario where you created a notification channel and user has decided that notifications from your app are of different priority as your app dictated. For this reason, your app can't be allowed to change user preference about your app's notifications, once they were given to user's control. The user could get unhappy, if your app had overridden their preference.

rafaellop commented 4 years ago

Well, I've played with the Android UI a bit and it seems the sound is back even if I don't specify own channel and fallback to the default. Sorry for misleading comment.

@misterti I didn't change channel name. I've only updated the plugin and the notification sound magically disappeared. I don't use any channel name so for the Katzer's plugin it used the "Default" channel if I good remember and indeed it is named "Default" if I check Android UI. I've also tried to uninstall and install again, clean app data and cache and no way the sound is bring back.

Steffaan commented 4 years ago

@misterti is right.

This is how Android is designed. Once the channel is made, no changes can be made to that specific channel.

Only way to get rid of those settings is by creating a new channel or reinstalling the application.