Custom Sound for Expo Push Notifications Only Works in Foreground
Minimal reproducible example
https://github.com/waelbenmustapha/pushNotifIssue
What platform(s) does this occur on?
Android
Did you reproduce this issue in a development build?
Yes
Summary
I'm developing an app with Expo and facing an issue with push notifications where the custom sound only plays when the app is in the foreground. When the app is backgrounded or closed, the notifications default to the system sound instead of the custom sound I've specified also it uses miscellaneous channelId. I can't understand why it's different in the background than in the foreground , the version im testing is an apk production build. I'm using Expo's managed workflow and sending notifications through their backend (expo-server-sdk). Here's how I configure the notification channel on the frontend:
await Notifications.setNotificationChannelAsync("ltsChannel", {
name: "ltsChannel",
sound: "sound.wav", // Custom sound file
importance: Notifications.AndroidImportance.MAX,
audioAttributes: {
usage: Notifications.AndroidAudioUsage.ALARM,
contentType: Notifications.AndroidAudioContentType.SONIFICATION,
},
});
And this is how I send notifications from the backend:
const messages = [];
messages.push({
to: pushToken,
sound: 'default',
title: 'Test Title',
body: 'Test Body',
channelId: "ltsChannel",
});
Environment
expo-env-info 1.2.0 environment info: System: OS: Windows 10 10.0.19045 Binaries: Node: 20.10.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.22 - ~\AppData\Roaming\npm\yarn.CMD npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: AI-223.8836.35.2231.10811636 npmPackages: expo: ~50.0.14 => 50.0.14 react: 18.2.0 => 18.2.0 react-native: 0.73.6 => 0.73.6 Expo Workflow: managed
Expo Doctor Diagnostics
✔ Check Expo config for common issues ✔ Check package.json for common issues ✔ Check native tooling versions ✔ Check dependencies for packages that should not be installed directly ✔ Check for common project setup issues ✔ Check npm/ yarn versions ✔ Check for issues with metro config ✔ Check Expo config (app.json/ app.config.js) schema ✔ Check that native modules do not use incompatible support packages ✔ Check for legacy global CLI installed locally ✔ Check that native modules use compatible support package versions for installed Expo SDK ✔ Check that packages match versions required by installed Expo SDK
Didn't find any issues with the project!
@waelbenmustapha I have forked your test repo, and built the Android app. Do you have working credentials so I can log in? Otherwise, we would need a more minimal repo that does not have a dependency on your service.
Having a possible related problem here. If I send a push notification when my app is in foreground the channel is respected and the corresponding settings are used. If the app is in the background or closed the notification ends up in a newly created "Miscellaneous" channel (id: fcm_fallback_notification_channel) resulting also in the notification not showing my app icon. I'm using expo 50.
@Mirthis having exactly the same issue, just wasted hours trying to figure out what's going on. I have correctly configured a channel and whenever I send to this channel (even via the online expo push notification tool: https://expo.dev/notifications) it still goes to the miscellaneous channel. I've seen other recent threads popping up online, seems like there is a bug/regression here which needs to be looked into cc @douglowder
Update on this, I have just found that it goes into my "general" channel whenever I send a push notification and the app is OPEN, however if the app is closed, in foreground, or phone is locked then the same push notification I am sending ends up in the miscellaneous channel. Any reason why this happens?
Hitting this wall too.
Tracking in ENG-12780
hey another question related to notifications , i sometimes don't receive push notifications , while other people do receive them , it's like maybe 10% of the times a notifications goes missing , is it normal ? i have the priority set to HIGH
@waelbenmustapha - Should you be sending notifications from the backend like this?
i.e. specifying the sound and not choosing default?
const messages = [];
messages.push({
to: pushToken,
sound: "sound.wav", // Custom sound file
title: 'Test Title',
body: 'Test Body',
channelId: "ltsChannel",
});
@waelbenmustapha - Should you be sending notifications from the backend like this?
i.e. specifying the sound and not choosing
default?sound: "sound.wav", // Custom sound file
The push notification request fails if the sound string is anything other than "default".
I can't even get the custom sound to work at all when sending from the back-end, regardless of the app being in the foreground, background, or killed.
We’re facing the same issue here. Any update?
Hello and thanks for reporting. Custom sounds are controlled by channels, and channel information was incorrectly handled by our push backend service. That issue is now resolved and does not require updating the expo-notifications package.
That means you should not be seeing this problem as of now. If you do, please open a new issue and follow the issue template.
Also see https://github.com/expo/expo/commit/c7e7205369a46b546828ed5bf50c8458628e96da
Thank you
@vonovak how about custom sound for iOS, it's still not working on managed apps using EAS Build. the documentation makes it like it works with both Android and iOS , it works perfectly fine on Android, but not on iOS
hello @SiddigHope Please open a new issue for your problem and follow the issue template. It's especially important that you include:
- runnable reproduction
- what behavior you're seeing (with steps to reproduce) and what you expect to see instead.
- For push notifications: the request you're sending to the push service in order to send the notification (especially the request body is important)
- Add the "Notifications" label to the Github Issue - this helps with visibility.
Thank you!
I am having the same problem.