Custom notification sounds doesn’t work on EAS built app.

Hi all, I built an apk with custom notification sounds using EAS.
I have included expo-notifications plugin and also other relevant APIs in my apk.

Workflow: managed
SDK version: 42

The following is some details of the configuration I have done:

image

image
where I include my sound file

image
relevant notification api

However, the custom notification sound doesn’t work when I sent a notification from FCM.

Is there a way to resolve this? or is there any mistake in the configuration?

Thanks.

So the local notification plays the sound, but not a push notification from FCM? What’s your FCM payload look like?

Hi @charliecruzan, both types of notifications could not play the sound I imported.
The payload will look like the following screenshot, this is from our backend:

image

and here’s another way I test (using postman):
image

sound is default there, what sound are you trying to play?

However, the custom notification sound doesn’t work when I sent a notification from FCM.

Is this happening in Expo Go, or your standalone app?

I was trying to play the sound I declare in the [ NotificationChannelInput ] inside the setNotificationChannalAsync API.

I have tried a different name for the identifier but still could not play the sound.
The following is the example:
API:
image

Push notification:
image

This is happening in my standalone app (Android - apk).

the sound should specify the sound file, and the you should specify the channel as new-notification

@charliecruzan Is this for [ setNotificationChannelAsync ] API ?(https://docs.expo.dev/versions/v42.0.0/sdk/notifications/#setnotificationchannelasyncidentifier-string-channel-notificationchannelinput-promisenotificationchannel--null)

If you are referring to that, we have specified the base filename of the sound file that we included in app.json. However, the app still failed to play custom sound.

image

Can you link your build logs to me?

Sure @charliecruzan.

Here is the link:

Hm, yeah the asset is definitely included in your APK, so the config plugin is working

I tested this with my own android build and the following code works:

await Notifications.setNotificationChannelAsync("new-one", {
    name: "default",
    importance: Notifications.AndroidImportance.MAX,
    vibrationPattern: [0, 250, 250, 250],
    lightColor: "#FF231F7C",
    sound: "cantina.wav",
  });
  await Notifications.scheduleNotificationAsync({
    content: {
      title: "You've got mail! 📬",
      body: "Here is the notification body",
      data: { data: "goes here" },
      sound: "cantina.wav",
    },
    trigger: {
      seconds: 2,
      channelId: "new-one", // <- for Android 8.0+, see definition above
    },
  });

in a standalone app built with EAS. You may want to try and debug this further locally by running expo run:android, which will build a debug version of your project and install it onto your connected device

Thanks for the tips @charliecruzan!

I tried the expo run: android to debug and use the same structure you mentioned. However, my custom notification sound still failed to play. Based on the logs, I realized that the value of the sound property is “custom” instead of what I specify in the code.
Is that the expected value we will see in the log?

image

{
  "date": 1629102035153,
  "request": Object {
    "content": Object {
      "autoDismiss": true,
      "badge": null,
      "body": "Here is the notification body",
      "data": Object {
        "data": "goes here",
      },
      "sound":"custom",
      "sticky": false,
      "subtitle": null,
      "title": "You've got mail! �",
    },
    "identifier": "4d28f1fa-16b0-47d1-ac96-1514d1aa1336",
    "trigger": Object {
      "channelId": "new-one",
      "repeats": false,
      "seconds": 2,
      "type": "timeInterval",
    },
  },
}

nope, that’s expected expo/packages/expo-notifications/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java at master · expo/expo · GitHub

Thank you for the clarification @charliecruzan !

Update:

I believe it was the length of the audio that causing the failure to play the custom sounds. The audio file I had was 2s long. I only realized this after I try to imported other audio with more than 3s length and managed to play it.

I then add one more second of silence in front my audio. Then, the custom notification sounds can be played.

1 Like

thanks for following up! must be an android limitation, I can try to find some docs on it (unless you already have?)

No worries @charliecruzan . Yea agree. I also exported the edited audio to a 8-bit wav file (mentioned this docs [Supported media formats  |  Android Developers]).

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.