Software Archive
Read-only legacy content
17061 Discussions

Customized OneSignal notification sound for app builded in Cordova Intel XDK?

Frungh_B_
Beginner
2,048 Views

I am using OneSignal to add push notifications to my hybrid app. Now that the notifications are working, I want to replace the default device's sound by my own Sound1.wav as mentioned here: https://documentation.onesignal.com/docs/android-notification-customizations#notification-sounds

I found that this is not straight forward in XDK since I have no access to the res/raw/ folder but there is a work around...
http://stackoverflow.com/questions/33995548/including-resources-folder-in-apk/34078623#34078623
However, this is still unsolved (and old solution I guess). 

I am trying to solve this by moving my sound file (located in <project>/www/) to the required folder by OneSignal (i.e. /res/raw/) 
during the XDK building process by modifying the intelxdk.config.additions.xml file as recommended here:
https://software.intel.com/en-us/xdk/docs/adding-special-build-options-to-your-xdk-cordova-app-with-the-intelxdk-config-additions-xml-file
So I did like this...

<platform name="android">
    <!-- below requires the splash screen plugin -->
    <!-- docs: https://github.com/apache/cordova-plugin-splashscreen -->
    <preference name="SplashMaintainAspectRatio" value="false" />
    
   <!-- This is my added line -->
    <resource-file src="www/sounds/Sound1.wav" target="res/raw/Sound1.wav" />
    
</platform>

Unfortunately this doesn't work. Is this the right approach to do solve this? How can I move the Sound1.wav from "www" folder  to the android folder "/res/raw/" and how can I see that the file is actually there after building?

0 Kudos
1 Solution
PaulF_IntelCorp
Employee
2,048 Views

Frungh -- you're on the right track. What you need to do is create a simple plugin that will add the resources you need to that Android system folder. See this FAQ for some hints on how to create a simple Cordova plugin > https://software.intel.com/en-us/xdk/faqs/general#android-manifest <

You could do this two ways:

  • find a plugin that does something similar for an example of the tags required to make that happen and create a small custom plugin that's only purpose is to get the additional resource files inserted into the right place
  • modify the OneSignal plugin (make a copy and modify it) and import it as a local plugin using the xdk plugin management tool

The first one is probably a better option, because it allows you to easily update the OneSignal plugin without having to modify it each time there is an update. However, the second one might be easier to get started.

If you do manage to create a simple plugin that does this, please post it here for the benefit of other XDK users.

p.s. This plugin shows an example of using the resource-file tag, but for an iOS device, not for Android > https://github.com/Puship/PushPlugin/blob/master/plugin.xml <

View solution in original post

0 Kudos
10 Replies
PaulF_IntelCorp
Employee
2,049 Views

Frungh -- you're on the right track. What you need to do is create a simple plugin that will add the resources you need to that Android system folder. See this FAQ for some hints on how to create a simple Cordova plugin > https://software.intel.com/en-us/xdk/faqs/general#android-manifest <

You could do this two ways:

  • find a plugin that does something similar for an example of the tags required to make that happen and create a small custom plugin that's only purpose is to get the additional resource files inserted into the right place
  • modify the OneSignal plugin (make a copy and modify it) and import it as a local plugin using the xdk plugin management tool

The first one is probably a better option, because it allows you to easily update the OneSignal plugin without having to modify it each time there is an update. However, the second one might be easier to get started.

If you do manage to create a simple plugin that does this, please post it here for the benefit of other XDK users.

p.s. This plugin shows an example of using the resource-file tag, but for an iOS device, not for Android > https://github.com/Puship/PushPlugin/blob/master/plugin.xml <

0 Kudos
PaulF_IntelCorp
Employee
2,048 Views

Here's the up-to-date reference for the plugin.xml file and that resource-file tag you need to use > https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#resource-file < combine that with the simple plugin.xml that I gave you in the FAQ pointer and you should be set to go. You'll need to create a "src/android" directory, like you see in a typical plugin to contain that mp3 file you want to move, so the Cordova plugin manager has it available when it performs the <resource-file> operation specified in your custom plugin's plugin.xml file.

0 Kudos
Frungh_B_
Beginner
2,048 Views

Paul F. (Intel) wrote:

Frungh -- you're on the right track. What you need to do is create a simple plugin that will add the resources you need to that Android system folder. See this FAQ for some hints on how to create a simple Cordova plugin > https://software.intel.com/en-us/xdk/faqs/general#android-manifest <

You could do this two ways:

  • find a plugin that does something similar for an example of the tags required to make that happen and create a small custom plugin that's only purpose is to get the additional resource files inserted into the right place
  • modify the OneSignal plugin (make a copy and modify it) and import it as a local plugin using the xdk plugin management tool

The first one is probably a better option, because it allows you to easily update the OneSignal plugin without having to modify it each time there is an update. However, the second one might be easier to get started.

If you do manage to create a simple plugin that does this, please post it here for the benefit of other XDK users.

p.s. This plugin shows an example of using the resource-file tag, but for an iOS device, not for Android > https://github.com/Puship/PushPlugin/blob/master/plugin.xml <

Thank you Paul, I follow your suggestions and finally manage to accomplish the task. I summarize the steps here for benefit of others.

1. Create a New Folder at any location (outside your project maybe) and give a name. I will call it from now... "SoundPlugin".

2. Inside the SoundPlugin folder create another folder, for example, "src". Place your target sound file inside that folder.

3. In the XDK go to File>>New.. and create the plugin that will move the audio files from folder SoundPlugin to the device during building. For a reference, here is one example for android devices, you can copy and paste this code and save this file as... plugin.xml which must be placed inside the SoundPlugin folder. Of course you must replace the corresponding folders and  Sound1.wav by your own folders and sounds in src="src/Sound1.wav".

<?xml version="1.0" encoding="UTF-8"?>  
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="sounds-onesignal-plugin" version="1.0.0"> 

    <name>Adding sounds to OneSignal push notification</name> 
    <description>Add customized sounds to the OneSignal push notifications service by moving the audio files to the requiered folders by OneSignal SDK</description> 
    <license>MIT</license> 

    <engines> 
        <engine name="cordova" version=">=3.0.0" /> 
    </engines>  

    <!-- android --> 
    <platform name="android">
        
        <!-- Replace Sound1.wav by your own sound -->
        <resource-file src="src/Sound1.wav" target="res/raw/Sound1.wav" />
                
    </platform>  
    
</plugin>

4. Open your project and go to the Plugin Manager to add this plugin (Third-Party Plugins >> Import local plugin >> select the folder SoundPlugin).

5. The plugin must appear now inside your project under the folder plugins with the given id name ("sounds-onesignal-plugin" if you just copy and paste the code in step 3).

6. Build your project and run the .apk in your device.

0 Kudos
PaulF_IntelCorp
Employee
2,048 Views

Frungh -- very glad to see that you got this working! Thank you for sharing your solution. :-)

0 Kudos
Luke_B_1
Beginner
2,048 Views

Frungh, thanks for the instructions. Do you know if it's possible to add complete folders? I have a folder with multiple sub-folders and multiple files. I don't want to add one-by-one if I can help it

0 Kudos
PaulF_IntelCorp
Employee
2,048 Views

Luke -- take a look at the Cordova documentation link, I think those it is limited to individual files. I've seen some plugins that use that feature that have some very long lists of files.

0 Kudos
Frungh_B_
Beginner
2,048 Views

Luke B. wrote:

Frungh, thanks for the instructions. Do you know if it's possible to add complete folders? I have a folder with multiple sub-folders and multiple files. I don't want to add one-by-one if I can help it

According to the cordova documentation is not possible to add complete folders using <resource-file>. However, you may wanna give a try by using <asset>. Let me know if this works.

https://cordova.apache.org/docs/en/latest/plugin_ref/spec.html#asset

 

0 Kudos
Eduardo_R_
Beginner
2,048 Views

I need to use that same process but with image icon to show when I send push notifications on onesignal. The default icon is a bell. I want to change that to my own icon. Any good step by step reference that benefit a good help?

0 Kudos
Giselle_G_Intel
Employee
2,048 Views

Eduardo R. wrote:

I need to use that same process but with image icon to show when I send push notifications on onesignal. The default icon is a bell. I want to change that to my own icon. Any good step by step reference that benefit a good help?

Check out the documentation for the API >https://documentation.onesignal.com/docs/android-customizations< it has links to customize the notifications.

0 Kudos
Gilgledson_S_
Beginner
2,048 Views

 i created a plugin cordova for add small icons in notification onesignal

link: https://github.com/gilgledson/onesignal-small-icon-add

 

0 Kudos
Reply