I’ve added OneSignal to an app for push notifications. They’re working well except the Android notifications don’t show our icon. I’ve followed their guide, but I can’t get it to work. Has anyone had luck with this?
Details on what I’ve tried:
I generated the icons and added them as below, and they show up in the cordova project on apparently the right path according to their guide. But the app stops receiving the notifications at all (whether triggered from their UI or by API). setExternalUserId
returns successfully, other devices receive the same push just fine but the app does not receive anything. Only when I remove the icons do the push notifications work again (with the default icon).
I’ve checked the icon files are the right sizes and added them on these paths below:
cordova-build-override/platforms/android/app/src/main/res/drawable-hdpi/ic_stat_onesignal_default.png
cordova-build-override/platforms/android/app/src/main/res/drawable-mdpi/ic_stat_onesignal_default.png
cordova-build-override/platforms/android/app/src/main/res/drawable-xhdpi/ic_stat_onesignal_default.png
cordova-build-override/platforms/android/app/src/main/res/drawable-xxhdpi/ic_stat_onesignal_default.png
cordova-build-override/platforms/android/app/src/main/res/drawable-xxxhdpi/ic_stat_onesignal_default.png
cordova-build-override/platforms/android/app/src/main/res/drawable-xxxhdpi/ic_onesignal_large_icon_default.png
And tried adding this to mobile-config.js
(thanks @matheusccastro):
const dest = '/platforms/android/app/src/main/res';
const source = `cordova-build-override/${dest}`;
const small = 'ic_stat_onesignal_default.png';
const large = 'ic_onesignal_large_icon_default.png';
App.addResourceFile(`${source}/drawable-mdpi/${small}`, `${dest}/drawable-mdpi/${small}`, 'android');
App.addResourceFile(`${source}/drawable-hdpi/${small}`, `${dest}/drawable-hdpi/${small}`, 'android');
App.addResourceFile(`${source}/drawable-xhdpi/${small}`, `${dest}/drawable-xhdpi/${small}`, 'android');
App.addResourceFile(`${source}/drawable-xxhdpi/${small}`, `${dest}/drawable-xxhdpi/${small}`, 'android');
App.addResourceFile(`${source}/drawable-xxxhdpi/${small}`, `${dest}/drawable-xxxhdpi/${small}`, 'android');
App.addResourceFile(`${source}/drawable-xxxhdpi/${large}`, `${dest}/drawable-xxxhdpi/${large}`, 'android');
I’ve tried several variations of the path, always either push stops working or it ignores the icon. The paths above seem most correct, both going by their documentation and in that the files end up in folders with lots of other files with similar names, for example:
But as mentioned, notifications stop arriving. What am I missing?
PS: I didn’t add a values/strings.xml
file as their documentation says. (When I do, the build process crashes, apparently due to another string file which they apparently already create on this path.) Instead, when I call their create notification API I add the property android_accent_color: 'FF5D31FF'
. This works; when I remove the images, push arrives fine and the default icon gets this color.