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

Custom Sound not working! #586

Closed
Kamoba opened this issue Jul 7, 2018 · 17 comments
Closed

Custom Sound not working! #586

Kamoba opened this issue Jul 7, 2018 · 17 comments

Comments

@Kamoba
Copy link

Kamoba commented Jul 7, 2018

Description:
Hi, Even based on the advice given on this post I still can't play a different sound when receiving the notification.
based on the documentation I modified my apk, created the res/raw folder in my apk file and put it my audio file (Alarm_Survivor.wav).

Environment
I use an html Android app (Thunkable).

I receive the notification with the following request (default sound):

{
  "app_id": "xxxxxxxxxxxxmyAppIDxxxxxxxxxxxxx",
  "included_segments": ["Active Users"],
  "android_sound": "Alarm_Survivor",
  "large_icon":"iconApp.png",
  "data": {"foo": "bar"},
  "contents": {"en": "Hello your alarm triggled!"}
}

I tryed different extension file .mp3 and .ogg, tryed rename audio file and tryed to put it on assets folder but nothing.

@rostopira
Copy link

@Kamoba if you have shrinkResources enabled in build.gradle, then you should explicitly tell shrinker to keep that file

@jkasten2
Copy link
Member

jkasten2 commented Jul 9, 2018

@Kamoba Android only supports lower case files in the res directory, the file name must contain only lowercase a-z, 0-9, or underscore. Normally Android Studio / Gradle will throw a build error when the file name does not match this format so double check the directory as well. Your sound file should be located at app/src/main/res/raw/alarm_survivor.wav.

If your app is targeting Android API 26 or higher then you will also need to setup a Category / Channel to support custom sounds on Android Oreo 8 and newer.
https://documentation.onesignal.com/docs/categories

@Kamoba
Copy link
Author

Kamoba commented Jul 15, 2018

Woohoo it's working! Thanks a lot gays!

@Kamoba Kamoba closed this as completed Jul 15, 2018
@sonicwong
Copy link

@rostopira
May you tell me how to make shrinker to keep that file?
I am using ionic 3.x

@rostopira
Copy link

@sonicwong I've never worked with ionic, but in native sdk you should add file keep.xml in res/xml folder with following content

<?xml version="1.0" encoding="utf-8"?>
<resources
    xmlns:tools="http://schemas.android.com/tools"
  
  tools:keep="@raw/your_sound_file,@drawable/maybe_some_picture"/>

This will tell shrinker to keep specific resources.

@KOSSOKO
Copy link

KOSSOKO commented Feb 2, 2019

@sonicwong did you find a solution ? I'm facing the same issue with ionic 3

@sonicwong
Copy link

sonicwong commented Feb 3, 2019

@KOSSOKO
just add below line inside platform tag in config.xml:

<resource-file src="resources/se/my.mp3" target="res/raw/my.mp3" />

this work fine on cordova android above v6.3.
there are some change in 6.4or later.

@KOSSOKO
Copy link

KOSSOKO commented Feb 3, 2019

@sonicwong thanks for you answer.
I added
<resource-file src="platforms/android/res/raw/onesignal_default_sound.mp3" target="platforms/android/res/raw/onesignal_default_sound.mp3" />
but still have no sound. I use Android 7.

@sonicwong
Copy link

@KOSSOKO, what cordova android version that u are using? try to downgrade to 6.3.

@nijeshw
Copy link

nijeshw commented Apr 29, 2019

Custom sound not working in Android Oreo 8 and newer, I have already created Category / Channel, here is my code

const notification: IOneSignalPushNotification = {

  include_player_ids: [this._userProfile.signalId],

  data: {

    redirect: "location",

  },

  contents: { en: 'This is test content' },

  large_icon: "https://s3.amazonaws.com/be-my-buddy-images/Logo_B%404x.png",

  priority: 4,

  ios_sound: 'sound8.wav',

  android_sound: 'sound8',

  android_channel_id: 'xxxxxxx-4462-xxxx-884a-xxxxxxxxxx'

};

In network http request all the given data was send successfully but when I check OneSignal delivery report the sound was default
Screenshot 2019-04-29 at 3 06 08 PM

Can any one help me here

@rostopira
Copy link

@nijesh17 Custom sound on Oreo must be linked to NotificationChannel
Then in onesignal console you must set notification channel and custom sound

@nijeshw
Copy link

nijeshw commented Apr 29, 2019

@rostopira Can you explain bit more

@KOSSOKO
Copy link

KOSSOKO commented Apr 29, 2019

@rostopira in my case, I have android 7, but can't be able to have custom sound.

@rostopira
Copy link

@KOSSOKO yeah, notification channels was introduced in nougat
@nijesh17 sorry, I don't have time for that

OneSignal team should add detailed instructions for that, I would suggest you to create separate issue for that

@KOSSOKO
Copy link

KOSSOKO commented Apr 29, 2019

@rostopira ok, I understand now why It doesnt work. Thanks a lot.

@ankitmeddo
Copy link

Those who has shrinkResources true in app/build.gradle.. Just remove this line and it will work.

@wellbranding
Copy link

I don't get the sound even after shrinking resources. Here is my issue:
#1072

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants