Skip to content
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

Unable to add custom sound for notification #477

Closed
KOSSOKO opened this issue Jan 19, 2019 · 16 comments
Closed

Unable to add custom sound for notification #477

KOSSOKO opened this issue Jan 19, 2019 · 16 comments

Comments

@KOSSOKO
Copy link

KOSSOKO commented Jan 19, 2019

Hi all, I use Ionic 3 with the latest version of onesignal. I have a back end that send a notification to my app. I'm tried without success to have a custom sound notification.

First, I create the sound and put it inside C:\Users\tkossoko\Documents\rdv-pref-app\app\V1\rdv-pref-app\platforms\android\res\raw\onesignalsound.mp3

In my back end, I send the notification like this

String jsonResponse;
			String sound = "onesignalsound";
			String small_icon = "ic_stat_onesignal_default";

			URL url = new URL("https://onesignal.com/api/v1/notifications");
			HttpURLConnection con = (HttpURLConnection)url.openConnection();
			con.setUseCaches(false);
			con.setDoOutput(true);
			con.setDoInput(true);

			con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
			con.setRequestMethod("POST");

			String strJsonBody = "{"
					+   "\"app_id\": \""+appId+"\","
					+   "\"include_player_ids\": ["+idsToSend+"],"
					+   "\"data\": {\"foo\": \"bar\"},"
					+   "\"android_sound\": \""+sound+"\","
					+   "\"small_icon\": \""+small_icon+"\","
					+   "\"contents\": {\"fr\": \""+message+"\",\"en\": \""+message+"\"}"
					+ "}";

But I still have the default notification sound. How could I do please ?
Thanks in advance.
@rgomezp rgomezp self-assigned this Jan 31, 2019
@rgomezp
Copy link
Contributor

rgomezp commented Jan 31, 2019

Hello @KOSSOKO ,
Please see this guide to edit the notification's sound on mobile https://documentation.onesignal.com/docs/customize-notification-sounds

Browsers do not currently support sounds on web push notifications. This feature is in development.

Chrome Thread: https://bugs.chromium.org/p/chromium/issues/detail?id=442131

Firefox Thread: https://bugzilla.mozilla.org/show_bug.cgi?id=1105222

With Android 8 you need to start adding sound through notification Categories aka Channels.

For more on Android Notification Categories, please see: https://documentation.onesignal.com/docs/android-notification-categories

For Android 7 and lower, you can add sound in the same way as before.

Please see this guide to edit the notification's sound on mobile https://documentation.onesignal.com/docs/customize-notification-sounds

@KOSSOKO
Copy link
Author

KOSSOKO commented Jan 31, 2019

Hi @rgomezp I followed steps mentioned in the first link you give, and with my android 7.0, I have no sound. I don't know how to do.

@rgomezp
Copy link
Contributor

rgomezp commented Jan 31, 2019

Try logging the sound variable and make sure that you are not including the file extension

@KOSSOKO
Copy link
Author

KOSSOKO commented Jan 31, 2019

@rgomezp How to logging the sound variable?
Yes, I double check that I didn't have the file extension.
It seems that the file is not copied into the apk during the build. I followed the documentation and placed the file in the folder specified.

@rgomezp
Copy link
Contributor

rgomezp commented Jan 31, 2019

I would recommend checking to make sure that the file is still there. You should be able to navigate to it using the file explorer. If it isn't getting copied to the APK, that sounds like something unrelated to the OneSignal SDK

@KOSSOKO
Copy link
Author

KOSSOKO commented Jan 31, 2019

I unzip my apk and in the res/raw folder, I have an xml file with the name consumer_one_signal_keep.xml instead of the soun, and in the content of this file, I have

<!-- onesignal_bgimage_notif_layout is always kept as it's id used directly in code.  -->
<resources xmlns:tools="http://schemas.android.com/tools"
           tools:keep="@drawable/ic_os_notification_fallback_white_24dp,@drawable/ic_stat_onesignal_default,@drawable/ic_onesignal_large_icon_default,@raw/onesignal_default_sound"
           tools:discard="@raw/consumer_onesignal_keep" />

<!-- Discard above doesn't seem to be working, file is added to .APK anyway but is only a packed size of 47 bytes.
     XML comments are always omitted from the .APK. -->

I have no idea if it is the correct behaviour or it's an issue.

@rgomezp
Copy link
Contributor

rgomezp commented Feb 1, 2019

Try naming it the same as the file defined in the keep file (onesignal_default_sound)

@KOSSOKO
Copy link
Author

KOSSOKO commented Feb 2, 2019

After renaming the file with onesignal_default_sound, I still have the same behaviour. I followed the documentation for Ionic, but I my custom sound is not used

@rgomezp
Copy link
Contributor

rgomezp commented Feb 12, 2019

We haven't gotten multiple reports of this issue. I wonder if you are perhaps doing something wrong

@KOSSOKO
Copy link
Author

KOSSOKO commented Feb 12, 2019

I really don't know. I followed the documentation step by step. And I tried many solutions on Stackoverflow, but any works for me.

@rgomezp
Copy link
Contributor

rgomezp commented Feb 21, 2019

My recommendation would be to try to reproduce the issue in a blank project and then if you want you can send us the project so we can help you take a closer look.

@KOSSOKO
Copy link
Author

KOSSOKO commented Feb 21, 2019

Ok, I will try with a blank project and give a feedback

@rgomezp
Copy link
Contributor

rgomezp commented Apr 23, 2019

Closing due to no response

@rgomezp rgomezp closed this as completed Apr 23, 2019
@Lucianotassara
Copy link

Hello, having the same issue since updated from ionic 3 to Ionic 4. Is there a solution? Thanks!

@DevJulianSalas
Copy link

Hello,

Browsers do not currently support sounds on web push notifications. This feature is in development.

Is this feature still in development? I have reviewed the documentation without results about sound in web push notifications.

@quizparlour
Copy link

Hi there i am unable to integrate custom sound notification even i have folllowed the documentation properly. could you please help me to debug and resolve it ?

@rgomezp rgomezp removed their assignment Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants