Custom notification sound not working

See original GitHub issue

Summary

I am trying to play custom sound when receiving notification. I am using eas build. I have added a wav sound in the following location: “./assets/sounds/notification_message.wav”. I added it to app.json using the expo-notification config plugin, then created a custom-dev client using eas build -p android --profile development.

The problem is that when sending a push notification using fcm or scheduling a notification with the sound property: “notification_message.wav”, the message is received but no sound. I am testing on android 6, so there is no channelId is needed as mention in the documentation.

image

image

expo prebuild shows that it is found in res/raw

image

Managed or bare workflow? If you have made manual changes inside of the ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

Package versions

“expo-dev-client”: “~0.8.4”, “expo-notifications”: “~0.14.0”,

Environment

Expo CLI 5.2.0 environment info: System: OS: Windows 10 10.0.19042 Binaries: Node: 16.14.0 - C:\Program Files\nodejs\node.EXE npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD npmPackages: expo: ^44.0.0 => 44.0.4 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: managed

Reproducible demo

https://github.com/ramiel1999/custom-notification-sound

import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
import React, { useState, useEffect, useRef } from "react";
import { Text, View, Button, Platform } from "react-native";

Notifications.setNotificationHandler({
    handleNotification: async () => ({
        shouldShowAlert: true,
        shouldPlaySound: true,
        shouldSetBadge: false,
    }),
});

export default function App() {
    useEffect(() => {
        registerForPushNotificationsAsync();
    }, []);

    return (
        <View
            style={{
                flex: 1,
                alignItems: "center",
                justifyContent: "space-around",
            }}
        >
            <Button
                title="Press to schedule a notification"
                onPress={async () => {
                    await schedulePushNotification();
                }}
            />
        </View>
    );
}

async function schedulePushNotification() {
    await Notifications.scheduleNotificationAsync({
        content: {
            title: "You've got mail! 📬",
            body: "Here is the notification body",
            data: { data: "goes here" },
            sound: "notification_message.wav",
        },
        trigger: { seconds: 2 },
    });
}

async function registerForPushNotificationsAsync() {
    let token;
    if (Constants.isDevice) {
        const { status: existingStatus } = await Notifications.getPermissionsAsync();
        let finalStatus = existingStatus;
        if (existingStatus !== "granted") {
            const { status } = await Notifications.requestPermissionsAsync();
            finalStatus = status;
        }
        if (finalStatus !== "granted") {
            alert("Failed to get push token for push notification!");
            return;
        }
    } else {
        alert("Must use physical device for Push Notifications");
    }

    return token;
}

Stacktrace (if a crash is involved)

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
itsramielcommented, Apr 2, 2022

Well for some reason with scheduled notifications and notifications sent with fcm you need to pass the vibrate property. It doesnt make sense why the vibrate property is needed to trigger the custom sound but it is needed.

3reactions
farhan-ibrahimcommented, Jun 15, 2022

Well for some reason with scheduled notifications and notifications sent with fcm you need to pass the vibrate property. It doesnt make sense why the vibrate property is needed to trigger the custom sound but it is needed.

I encountered this issue as well. It’s only working if I include vibrate:false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top 10 Ways to Fix Notification Sound Not Working on Android
1. Check Notification Volume · 2. Enable Sound Profile · 3. Turn off DND · 4. Check Notification Sound Settings for Apps ·...
Read more >
A reason why custom notification sound might not work on ...
First of all, we should remove the notification channel and create a new one with a new notification channel id. Secondly, we should...
Read more >
12 Best Fixes for Samsung Notification Sounds Not Working
1. Restart Phone · 2. Check and Increase Notification Volume Level · 3. Disable Mute or Vibration Mode · 4. Disable Separate App...
Read more >
Sound Notifications Not Working - Android - Voxer Support
Try these steps: Go to Settings > Sound & Notification > App Notifications. Select the app, and make sure that Notifications are turned...
Read more >
Custom notification sounds not showing up
Try going to Settings>Apps, and tap Menu>Reset All App Preferences. Now try setting the notification tone again. Does it ask you to choose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found