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 notification sound is not played while the app is in foreground #1388

Closed
PuscasAdi opened this issue Jan 24, 2023 · 6 comments · Fixed by #1657
Closed

Custom notification sound is not played while the app is in foreground #1388

PuscasAdi opened this issue Jan 24, 2023 · 6 comments · Fixed by #1657

Comments

@PuscasAdi
Copy link

Bug Report

Plugin(s)

@capacitor/push-notifications": "^4.0.0"

Capacitor Version

Latest Dependencies:

  @capacitor/cli: 4.6.2
  @capacitor/core: 4.6.2
  @capacitor/android: 4.6.2
  @capacitor/ios: 4.6.2

Installed Dependencies:

  @capacitor/cli: 4.6.1
  @capacitor/ios: 4.6.1
  @capacitor/core: 4.6.1
  @capacitor/android: 4.6.1

Platform(s)

Android

Current Behavior

I created an android notification channel and a custom notification sound for it. The issue is that the custom sound only plays while the user has the app closed or in background.

Expected Behavior

The custom notification sound should be played even if the app is in foreground.

Code Reproduction

await PushNotifications.createChannel(
            {id: 'orders', name: 'orders', importance: 3, sound: 'order_sound'}
      );

Other Technical Details

Additional Context

@ionitron-bot ionitron-bot bot added the triage label Jan 24, 2023
@ionitron-bot ionitron-bot bot removed the triage label Jan 24, 2023
@PuscasAdi PuscasAdi changed the title Custom notification sound is not played while the app in in foreground Custom notification sound is not played while the app is in foreground Jan 24, 2023
@Ionitron
Copy link
Collaborator

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks!
Ionitron 💙

@RaddishIoW
Copy link

Could be related to #1368

@RaddishIoW
Copy link

I created a PR which should fix this issue - it will allow you to use a custom channel for foreground notifications.

@RaddishIoW
Copy link

This is caused by the fact that the plugin creates it's own special channel for displaying notifications when the app is in the foreground (and you have the 'alert' presentation option set in the config for the plugin).
Subsequently, all notifications received when the app is in the foreground ignore the channel specified in the notification payload and instead post to this special foreground channel. Currently, there is no control over this behaviour or the sound played for this channel.

My PR (#1423) fixes this by allowing you to specify a sound, or in fact specify the channel yourself for foreground notifications.

@RaddishIoW
Copy link

I've given up and created my own plugin to fix this, in case anyone comes across this...
@haylltd/capacitor-push-notifications
It's a drop-in replacement for the official plugin. PRs welcome.

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 22, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.