Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 2948bb6

Browse files
committed
Prevent sound to be mute in default state.
1 parent fe5b521 commit 2948bb6

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,13 @@ public void sendToNotificationCentre(Bundle bundle) {
369369
}
370370

371371
soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resId);
372-
373-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
374-
channel_id = channel_id + "-" + soundName;
375-
}
376372
}
373+
} else {
374+
soundName = "default";
375+
}
376+
377+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
378+
channel_id = channel_id + "-" + soundName;
377379
}
378380

379381
notification.setSound(soundUri);
@@ -687,10 +689,13 @@ public void checkOrCreateDefaultChannel() {
687689
NotificationManager manager = notificationManager();
688690

689691
int importance = NotificationManager.IMPORTANCE_HIGH;
692+
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
693+
694+
String channel_id_sound = NOTIFICATION_CHANNEL_ID + "-default-" + importance + "-" + DEFAULT_VIBRATION;
695+
checkOrCreateChannel(manager, channel_id, soundUri, importance, new long[] {0, DEFAULT_VIBRATION});
690696

691-
String channel_id = NOTIFICATION_CHANNEL_ID + "-" + importance + "-" + DEFAULT_VIBRATION;
692-
693-
checkOrCreateChannel(manager, channel_id, null, importance, new long[] {0, DEFAULT_VIBRATION});
697+
String channel_id_no_sound = NOTIFICATION_CHANNEL_ID + "-" + importance + "-" + DEFAULT_VIBRATION;
698+
checkOrCreateChannel(manager, channel_id_no_sound, null, importance, new long[] {0, DEFAULT_VIBRATION});
694699
}
695700

696701
private void checkOrCreateChannel(NotificationManager manager, String channel_id, Uri soundUri, int importance, long[] vibratePattern) {

0 commit comments

Comments
 (0)