How To Automatically Copy OneSignal Custom Notification Icons Into The Android Resources Directories For Ionic Projects

If you are using OneSignal for your push notifications in your Ionic project then here’s a useful hook to automatically copy your custom icons into your android resources folder.

The OneSignal Ionic SDK installation is here and the note about custom android notification icons is here which links to the custom android notification generator.

Once you have generated your icons and downloaded them follow these instructions:

1) Create a directory at the root of your project called ‘onesignal’, extract the files from ic_stat_onesignal_default.zip into it

2) Add a file to your ‘hooks’ directory inside the ‘after_prepare’ folder called ‘030_copy_android_notification_icons.js’

Put the following code in it:

(Many thanks to DevGirl for the code that I have adapted for this tutorial. See the original blog post here)

3) From the root of your project make the file executable:

4) Run ionic prepare

And your files will be copied into the correct directories for your android project

One thought on “How To Automatically Copy OneSignal Custom Notification Icons Into The Android Resources Directories For Ionic Projects

  • Thanks! This was really helpful.

    I had to add to the hook the script to create the folders if they do not exists though.
    I added this just before the line “if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {”

    var destfolder = destfile.split(‘/’);
    destfolder.pop();
    destfolder = destfolder.join(‘/’);
    if (!fs.existsSync(destfolder)) {
    fs.mkdirSync(destfolder);
    }

Leave a Reply