-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android - No sound on notifications? #1432
Comments
okay so this might sound a little stupid but it might be an issue for you too. I was using the whole string instead of just using
You just have to use the exact name, not the whole string. I think someone should look at the comment which is written in the latest commit. |
Oh. My default sound was playing fine. My version is
and I am testing on my Samsung Note 8. |
I've tested on a Pixel 2 (Android 10) and Motorola G5 (Android 8.1), neither seem to work. It seems like the notification channel is created muted as default. |
Can you show the code? |
Sample Code:
|
Check in ur Settings -> Notification -> Your App -> Sound, is a sound chosen? |
Hum... Can you try to change in your node_modules, the file mentioned and change: if (!bundle.containsKey("playSound") || bundle.getBoolean("playSound")) {
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String soundName = bundle.getString("soundName");
if (soundName != null) {
if (!"default".equalsIgnoreCase(soundName)) {
// sound name can be full filename, or just the resource name.
// So the strings 'my_sound.mp3' AND 'my_sound' are accepted
// The reason is to make the iOS and android javascript interfaces compatible
int resId;
if (context.getResources().getIdentifier(soundName, "raw", context.getPackageName()) != 0) {
resId = context.getResources().getIdentifier(soundName, "raw", context.getPackageName());
} else {
soundName = soundName.substring(0, soundName.lastIndexOf('.'));
resId = context.getResources().getIdentifier(soundName, "raw", context.getPackageName());
}
soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
channel_id = channel_id + "-" + soundName;
}
}
}
notification.setSound(soundUri);
} By: if (!bundle.containsKey("playSound") || bundle.getBoolean("playSound")) {
soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
String soundName = bundle.getString("soundName");
if (soundName != null) {
if (!"default".equalsIgnoreCase(soundName)) {
// sound name can be full filename, or just the resource name.
// So the strings 'my_sound.mp3' AND 'my_sound' are accepted
// The reason is to make the iOS and android javascript interfaces compatible
int resId;
if (context.getResources().getIdentifier(soundName, "raw", context.getPackageName()) != 0) {
resId = context.getResources().getIdentifier(soundName, "raw", context.getPackageName());
} else {
soundName = soundName.substring(0, soundName.lastIndexOf('.'));
resId = context.getResources().getIdentifier(soundName, "raw", context.getPackageName());
}
soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resId);
}
} else {
soundName = "default";
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
channel_id = channel_id + "-" + soundName;
}
notification.setSound(soundUri);
} |
Changed the above, re-sync gradle, did gradlew clean and react-native run-android but it didn't work for me. The Sound selected by default is still "None" instead of the default sound. Edit: Mine is remote notification though |
@Gabsys |
Sound is available, but no chosen ("no sound" / "none"). Of course I could choose a sound there, and then it works, but it should be turned on by default. |
@Dallas62 what about iOS local notifications? They seem muted as well, |
Yes, I face the same issue. I believe @Dallas62 is fixing it now |
Hi,
OR
|
You probably need to reinstall the application, but if this is already released, you can also set: <meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="rn-push-notification-channel-id-default-4-300" /> in AndroidManifest |
Hi @Dallas62 , My bet, It could be something to do with the payload sent through the FCM as well. The Payload which I'm trying to send
On Foreground When I console notification of onNotification(notification)
As you see the sound:"sound.mp3" is received as "sound", Is that could be an issue? I also tried installing the dev & set the above lines in AndroidManifest, No result. |
Hi @anishsrinivasan |
Do we need this even if we only use local notifications? I will try to test it once I get time. |
This is not needed for local notification, only remote. |
@Dallas62 The #dev version solves the problem for local notifications with default sound for me. Thank you very much! When can we expect a new version with this fix? |
Hi @hubermat |
Sounds seem to be fixed in the latest release, but now they somehow defeat the volume settings of the OS. I've got my notification volume silenced and the notifications for this app come out at full volume anyway. Some of our users reported it's really soft for them, despite having their phones set at full volume. |
Hi @wbercx <meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="rn-push-notification-channel-id-default-4-300" /> But it seems like there is an issue with DND which is ignored, I'm looking into it. |
@Dallas62 Nah, local notifications. It appears to be using the Alarm volume, rather than Notification/Ringtone volumes. If I go to the Clock app and I change the alarm volume in there, that affects the next notification that is displayed. So far this seems to work, but I haven't done thorough testing yet: AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .setUsage(AudioAttributes.USAGE_ALARM)
+ .setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build(); |
@wbercx This change works and solve the DND issue ! 🚀 |
@Dallas62 Nice! That's one other thing I noticed. It creates two channels now - one with sound and one without - but it uses the same name for both. While some of our users tried to work out why it was so quiet, they were wondering why the same entry appeared twice in the Settings app. Could we dynamically add |
@wbercx I can implement a solution to select a name / description based on the ID, and fallback to the default (like the actual behaviour). By changing: public String getChannelName()
public String getChannelDescription() To public String getChannelName(String channel_id)
public String getChannelDescription(String channel_id) in |
I will release a fix for the current issue, and push on |
The version
I will test it later today, AndroidManifest should be updated like this: <meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="DEFAULT NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="DEFAULT NOTIFICATION CHANNEL DESCRIPTION"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.CHANNEL_ID"
android:value="YOUR CHANNEL_ID NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.CHANNEL_ID"
android:value="YOUR CHANNEL_ID NOTIFICATION CHANNEL DESCRIPTION"/> Default channels id:
|
@Dallas62 You're a legend, thanks for the quick turnaround on everything! Much appreciated! |
Just to be sure, we need to use the channels |
Hi @cristianoccazinsp
Since ID are generated based on local notification parameters (🤮) you can use "custom" channel id if they follow this pattern: |
Thanks. As long as it is documented, I don't think it is so bad. I haven't been able to test the updates yet, but I will let you know how it goes once I do it. |
Apparently even on |
@Dallas62 just tried this for local notifications, and it seems to be working fine! I didn't have to change the manifest at all, can you clarify if that's required, or just optional if we want custom names for each notification channel? My current manifest:
|
Hi @cristianoccazinsp |
Hi @d0xi5 |
Tried it on Android and Im getting no sound. I have my file in raw directory, and Im receiving the notification but its not vibrating nor making any sound. I tried with 'default' and nothing. I have also checked the permissions under the app for sound and they are fine. |
I have added on manifiest the following: `
` And on NotifService.js `
scheduleNotif(soundName, time, title, subtitle) {
} Am I missing something? |
Hi @d0xi5 Did you try to make a fresh install of the application or change the notification id ? |
@Dallas62 I have tried both things and no luck. Just the notification but without sound and without vibration. Phone is on sound mode. I couldn't try example app, I had some errors on Android Studio. |
Found the issue, I was doing
Inside the component (hooks), and the channel was being created a lot of times. I passed that code outside of it Thank you for you quick reply @Dallas62 |
Hi @Dallas62, How to make turn on sound by default? Did we fixed it on new version? Thank you |
how can we play a custom sound in remote notification ? is there any solution ? Thanks in advance |
First, giving 4 to the importance parameter. |
I have a similar problem, If I create a channel and set the soundName as "default" or just remove it, it will always play the default sound, even when I schedule a notification with another custom sound. on the latest 7.2.3 version. |
Hi @UxmanKaxmi |
@cristianoccazinsp Hi, could you tell me how did you manage to turn on the sound in the chanell configuration, as you write in the opening post? My function for scheduling local notifications looks like this (the notification is shown at the right time, but without sound). |
The code looks fine , what about the channel configuration? Chances are you may need to uninstall and re install the app if the channel was already created as muted.
|
@cristianoccazinsp Thank you for replying. I am using AVD and if I understand it correctly it installs the app each time I start up the envirorment. I have tried adding your code to the constructor, but it didnt help (the virtual device plays other sounds from the app, like clicking a button, so I think the problem is not with the emulator). `
} export default new Notifications(); The Notifications class is singleton (instantiated in App.js) which is passed to other components. I then use the scheduleNotification() function to set notifications, which are displayed on time, just without sound (and since the whole point of the app is to be an alarm clock, this is a huge problem for me). |
Have you tried if regular notifications instead of scheduled ones make any sound? Also, go to the OS app settings and check how was the notificación created. Lastly, try to test on a real device too, it could be many things. |
How can we ask for this permission when the app opens? |
-> Your channelId and channelName should be same. |
The sound in notifications does not work when the app is in the background, can someone help? |
using this permission play store reject your app in play store i have problem in realme device didnt get notification custom sound working fine in all devices for MI phones i turn on auto restart toggle from setting of device any idea how to do it in realme narzo UI 5.0 |
Bug
Using
{playSound: true, soundName: 'default'}
doesn't work withlocalNotification
. This affects both iOS and Android. Are there limitations on local notifications? I am able to turn on sound on Android if I configure the notification channel (from the OS settings) to use sound.Environment info
Library version: 3.4.0
Steps To Reproduce
The text was updated successfully, but these errors were encountered: