cordova-plugin-background-mode
cordova-plugin-background-mode copied to clipboard
[Question] How do I set a custom icon for the notification?
I am trying to set up a custom icon so it no longer shows the white square, but I can't seem to get it to target a new icon. How do i include more icons in my project and aim this plugin to use a new icon?
I tried adding <resource-file src="img_res/icons/android/icon_noti.png" target="res/drawable/iconnoti.png" />
to my config
<platform name="android">
<resource-file src="img_res/icons/android/icon_noti.png" target="res/drawable/iconnoti.png" />
<icon density="ldpi" src="img_res/icons/android/ldpi.png" />
<icon density="mdpi" src="img_res/icons/android/mdpi.png" />
<icon density="hdpi" src="img_res/icons/android/hdpi.png" />
<icon density="xhdpi" src="img_res/icons/android/xhdpi.png" />
<icon density="xxhdpi" src="img_res/icons/android/xxhdpi.png" />
<icon density="xxxhdpi" src="img_res/icons/android/xxxhdpi.png" />
<splash density="port-ldpi" src="img_res/screens/android/splash-port-ldpi.png" />
<splash density="port-mdpi" src="img_res/screens/android/splash-port-mdpi.png" />
<splash density="port-hdpi" src="img_res/screens/android/splash-port-hdpi.png" />
<splash density="port-xhdpi" src="img_res/screens/android/splash-port-xhdpi.png" />
<splash density="port-xxhdpi" src="img_res/screens/android/splash-port-xxhdpi.png" />
<splash density="port-xxxhdpi" src="img_res/screens/android/splash-port-xxxhdpi.png" />
</platform>
And using it like this
cordova.plugins.backgroundMode.setDefaults({
resume: true,
hidden: false,
bigText: false,
icon:'iconnoti'
});
When I search the platforms folder, it did add the icon to the drawable folder. But I still get the white square. I tried different icons, black on transparent, white on transparent, xxxhdpi size, ldpi size, but always a white square.
I'm a bit lost on this. I don't want to lose the colour icon in the launcher. How do I add an extra icon to the app, and have the plugin use the icon?
Thanks
Hopefully someone can tell me I did this wrong because this is what I ended up having to do
<platform name="android">
<resource-file src="img_res/icons/android/ldpinoti.png" target="res/mipmap-ldpi/iconnoti.png" />
<resource-file src="img_res/icons/android/mdpinoti.png" target="res/mipmap-mdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/hdpinoti.png" target="res/mipmap-hdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/xhdpinoti.png" target="res/mipmap-xhdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/xxhdpinoti.png" target="res/mipmap-xxhdpi/iconnoti.png" />
Specifically to the mipmap folder, not the drawable folder, even though documentation says both should work. I had to follow this https://www.creativefreedom.co.uk/icon-designers-blog/android-4-1-icon-size-guide-made-simple/ to make some of the icon sizes, and ldpi from another site. iconColor doesn't work (but if it did, it would be undocumented) but icon did. With everything like this, I was able to set an icon for notification.
Update for Cordova Android 7.1's new file layout
<platform name="android">
<resource-file src="img_res/icons/android/ldpinoti.png" target="app/src/main/res/mipmap-ldpi/iconnoti.png" />
<resource-file src="img_res/icons/android/mdpinoti.png" target="app/src/main/res/mipmap-mdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/hdpinoti.png" target="app/src/main/res/mipmap-hdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/xhdpinoti.png" target="app/src/main/res/mipmap-xhdpi/iconnoti.png" />
<resource-file src="img_res/icons/android/xxhdpinoti.png" target="app/src/main/res/mipmap-xxhdpi/iconnoti.png" />
@TDola Thanks for the help and guidance!
@TDola @ansongoldade Thanks! I'm having trouble setting that appropriate icon, icon name, at the right folder, ect. I wish there was a repo of an android project where i could see explicitely how to setDefaults for the notification tray entry when the app goes in backjground, as of now, its not the right message and brings me to the app info setting instead of bringing back the app on foreground!
When giving tips it seems people know exactly what the other guy meant by 'setuping the icon at the right place with the right name etc.'
If anyone could provide more explicit explanations as to how to set defaults for notification tray icon for newbies who dont know where to put files, how to have android copy them in the right folder, etc..
Thanks in advance!
THanks! I've got it to work with this :
cordova.plugins.backgroundMode.setDefaults({
title: 'Dispatch Application',
text: 'Running in background',
icon: 'ic_launcher',
color: "0E4291",
resume: true,
hidden: false,
bigText: false
});
I'm just using cordova and the terminal window, no android studio IDE. so it looks like ic_launcher.png was a special icon that was available to use for that., seems to work, not sure if i'm doing the optimal thing....
Many thanks again!
Update for Cordova Android 7.1's new file layout
<platform name="android"> <resource-file src="img_res/icons/android/ldpinoti.png" target="app/src/main/res/mipmap-ldpi/iconnoti.png" /> <resource-file src="img_res/icons/android/mdpinoti.png" target="app/src/main/res/mipmap-mdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/hdpinoti.png" target="app/src/main/res/mipmap-hdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/xhdpinoti.png" target="app/src/main/res/mipmap-xhdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/xxhdpinoti.png" target="app/src/main/res/mipmap-xxhdpi/iconnoti.png" />
This guide does not allow you to customize the notification icon, because it uses the same launch icon that is installed with the application.
Update for Cordova Android 7.1's new file layout
<platform name="android"> <resource-file src="img_res/icons/android/ldpinoti.png" target="app/src/main/res/mipmap-ldpi/iconnoti.png" /> <resource-file src="img_res/icons/android/mdpinoti.png" target="app/src/main/res/mipmap-mdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/hdpinoti.png" target="app/src/main/res/mipmap-hdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/xhdpinoti.png" target="app/src/main/res/mipmap-xhdpi/iconnoti.png" /> <resource-file src="img_res/icons/android/xxhdpinoti.png" target="app/src/main/res/mipmap-xxhdpi/iconnoti.png" />
This guide does not allow you to customize the notification icon, because it uses the same launch icon that is installed with the application.
Duplicate those resource lines for every additional icon you need.
Also this plugin is a little bit dead. Try this fork https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background/src/master/ Currently working on android X support