diff --git a/android/app/src/main/java/com/expensify/chat/customairshipextender/CustomNotificationProvider.java b/android/app/src/main/java/com/expensify/chat/customairshipextender/CustomNotificationProvider.java
index 3d16e607be49..8eff32dedf76 100644
--- a/android/app/src/main/java/com/expensify/chat/customairshipextender/CustomNotificationProvider.java
+++ b/android/app/src/main/java/com/expensify/chat/customairshipextender/CustomNotificationProvider.java
@@ -15,6 +15,8 @@
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
+import android.media.AudioAttributes;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.service.notification.StatusBarNotification;
@@ -31,6 +33,7 @@
import androidx.core.graphics.drawable.IconCompat;
import androidx.versionedparcelable.ParcelUtils;
+import com.expensify.chat.R;
import com.urbanairship.AirshipConfigOptions;
import com.urbanairship.json.JsonMap;
import com.urbanairship.json.JsonValue;
@@ -105,6 +108,9 @@ protected NotificationCompat.Builder onExtendBuilder(@NonNull Context context, @
builder.setChannelId(CHANNEL_MESSAGES_ID);
} else {
builder.setPriority(PRIORITY_MAX);
+ // Set sound for versions below Oreo
+ // for Oreo and above we set sound on the notification's channel level
+ builder.setSound(getSoundFile(context));
}
// Attempt to parse data and apply custom notification styling
@@ -130,6 +136,13 @@ private void createAndRegisterNotificationChannel(@NonNull Context context) {
NotificationChannelGroup channelGroup = new NotificationChannelGroup(NOTIFICATION_GROUP_CHATS, CHANNEL_GROUP_NAME);
NotificationChannel channel = new NotificationChannel(CHANNEL_MESSAGES_ID, CHANNEL_MESSAGES_NAME, NotificationManager.IMPORTANCE_HIGH);
+ AudioAttributes audioAttributes = new AudioAttributes.Builder()
+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION)
+ .build();
+
+ channel.setSound(getSoundFile(context), audioAttributes);
+
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannelGroup(channelGroup);
notificationManager.createNotificationChannel(channel);
@@ -333,4 +346,8 @@ private Bitmap fetchIcon(@NonNull Context context, String urlString) {
return null;
}
+
+ private Uri getSoundFile(Context context) {
+ return Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.receive);
+ }
}
diff --git a/ios/NotificationServiceExtension/NotificationService.swift b/ios/NotificationServiceExtension/NotificationService.swift
index c4eb01981bf2..e489cb368d17 100644
--- a/ios/NotificationServiceExtension/NotificationService.swift
+++ b/ios/NotificationServiceExtension/NotificationService.swift
@@ -24,6 +24,8 @@ class NotificationService: UANotificationServiceExtension {
return
}
+ bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName("receive.mp3"))
+
if #available(iOSApplicationExtension 15.0, *) {
configureCommunicationNotification(notificationContent: bestAttemptContent, contentHandler: contentHandler)
} else {
diff --git a/src/libs/Sound/playSoundExcludingMobile/index.native.ts b/src/libs/Sound/playSoundExcludingMobile/index.native.ts
new file mode 100644
index 000000000000..c41ad6998483
--- /dev/null
+++ b/src/libs/Sound/playSoundExcludingMobile/index.native.ts
@@ -0,0 +1,2 @@
+// mobile platform plays a sound when notification is delivered (in native code)
+export default function playSoundExcludingMobile() {}
diff --git a/src/libs/Sound/playSoundExcludingMobile/index.ts b/src/libs/Sound/playSoundExcludingMobile/index.ts
new file mode 100644
index 000000000000..03c5cd57a635
--- /dev/null
+++ b/src/libs/Sound/playSoundExcludingMobile/index.ts
@@ -0,0 +1,5 @@
+import playSound from '..';
+
+const playSoundExcludingMobile: typeof playSound = (sound) => playSound(sound);
+
+export default playSoundExcludingMobile;
diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts
index 2280f6cdc0f5..d7cef2aca546 100644
--- a/src/libs/actions/User.ts
+++ b/src/libs/actions/User.ts
@@ -29,6 +29,7 @@ import * as Pusher from '@libs/Pusher/pusher';
import PusherUtils from '@libs/PusherUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import playSound, {SOUNDS} from '@libs/Sound';
+import playSoundExcludingMobile from '@libs/Sound/playSoundExcludingMobile';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
@@ -527,12 +528,12 @@ function playSoundForMessageType(pushJSON: OnyxServerUpdate[]) {
// mention user
if ('html' in message && typeof message.html === 'string' && message.html.includes(`@${currentEmail}`)) {
- return playSound(SOUNDS.ATTENTION);
+ return playSoundExcludingMobile(SOUNDS.ATTENTION);
}
// mention @here
if ('html' in message && typeof message.html === 'string' && message.html.includes('')) {
- return playSound(SOUNDS.ATTENTION);
+ return playSoundExcludingMobile(SOUNDS.ATTENTION);
}
// assign a task
@@ -552,7 +553,7 @@ function playSoundForMessageType(pushJSON: OnyxServerUpdate[]) {
// plain message
if ('html' in message) {
- return playSound(SOUNDS.RECEIVE);
+ return playSoundExcludingMobile(SOUNDS.RECEIVE);
}
}
} catch (e) {