katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.76k forks source link

Icon is not showing #1863

Closed ran-j closed 1 month ago

ran-j commented 4 years ago

WARNING: IF YOU IGNORE THIS TEMPLATE, WE'LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

Expected Behavior

icon on notification.

Actual Behavior

Icons are not displaying, I spend hours reading issues and I cant make it work.

My config:

<platform name="android">
        <allow-intent href="market:*" />
        <resource-file src="google-services.json" target="app/google-services.json" />
        <resource-file src="www/res/drawable-hdpi/myandroid.png" target="res/drawable-hdpi/myandroid.png" />
        <resource-file src="www/res/mipmap-mdpi/myandroid.png" target="res/mipmap-mdpi/myandroid.png" />
    </platform>

This is the icon : https://material.io/resources/icons/?icon=android&style=baseline

And my code :

cordova.plugins.notification.local.schedule({
            id: 15,
            title: 'Chat with Irish',
            icon: 'res://myandroid',
            smallicon: 'res://myandroid',
            text: [
                { message: 'I miss you' },
                { person: 'Irish', message: 'I miss you more!' },
                { message: 'I always miss you more by 10%' }
            ]
        });

And then image

ivanov84 commented 4 years ago

in cordova 9.0.0 target folder changed - please add app/src/main path for target

ran-j commented 4 years ago

Add where ?

ivanov84 commented 4 years ago

@ran-j here:

`

`

ran-j commented 4 years ago

image

the icon works but smalicon dont

timkellypa commented 4 years ago

I think it should be "smallIcon" (with a capital i).

boltex commented 4 years ago

@timkellypa @ran-j Do you guys have prohjects on github where i could see your whole setup of how you guys did it - I cant seem to set icons at all with this plugin!

(the docs are not specific, they merely mention things without detailing each options carefully)

timkellypa commented 4 years ago

@boltex Unfortunately, I have nothing really to share, although when I find some time, I may attempt to build a quick sandbox for this if nobody has already. I agree that the docs aren't very descriptive, but if you look at CHANGELOG.md, that is sometimes more helpful.

The important bits for the icon, I think, are that your config.xml should have your resources in it under the Android node. They should appear as follows:

`

    <resource-file src="www/path-to-your-image/48.png" target="app/src/main/res/drawable-xhdpi/icon_key.png" />
    <resource-file src="www/path-to-your-image/72.png" target="app/src/main/res/drawable-xxhdpi/icon_key.png" />
    <resource-file src="www/path-to-your-image/96.png" target="app/src/main/res/drawable-xxxhdpi/icon_key.png" />`

Then you just use "res://name-of-your-target" as the path for icon and smallIcon. So for this example it would be

smallIcon: 'res://icon_key'

If you see a blank gray box for your icons, this just means that you are on a device that only supports monochrome icons. I think that is Android 7 and 8 (maybe? They re-added support for multi-color icons in more recent versions.) If you're using or testing on any of those devices, the trick is to make your icon any color you want (the OS will make it gray or white depending on when it is displayed), but make the background transparent. The system will use that to create a monochrome image in the notification.

boltex commented 4 years ago

I see, Thank you!

My config.xml only has the src parts, not the target parts, its an ooder cordova project that I upgraded to a more recent cordova-android platform...

anyways,

Many thanks again!