arnesson / cordova-plugin-firebase

Cordova plugin for Google Firebase
http://arnesson.github.io/cordova-plugin-firebase
MIT License
1.01k stars 1.56k forks source link

set different small icon and large icon for notification #803

Open steeper opened 6 years ago

steeper commented 6 years ago

I been wondering if there is a way to set a different LargeIcon and Small Icon in the notification, as cordova-plugin-local-notifications does. I saw the code for both plugins and the only thing missing is the .setLargeIcon parameter in cordova-plugin-firebase but I don't know if this is correct and will work. Not so good with this code at the moment, I read what #764 says but you have to send the parameter from firebase console or by code. Is there a way it can be created with two different icons without sending params from the back in the json? Thanks for the help 😄

christianguevara commented 5 years ago

In the config.xml i'm using this for android:

<resource-file src="resources/android/notification_icon/drawable-mdpi/notification_icon.png" target="app/src/main/res/drawable-mdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-hdpi/notification_icon.png" target="app/src/main/res/drawable-hdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xhdpi/notification_icon.png" target="app/src/main/res/drawable-xhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxxhdpi/notification_icon.png" />
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
</config-file>
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:value="@color/accent" />
</config-file>

It does copy the resources in resources/android/notification_icon/drawable-***/notification_icon.png to the android respective folders and references them later in the manifest, i tested this and it works, maybe try it.

The icons are generated in here

rhanesoghlyan commented 5 years ago

@christianguevara I got a error AAPT: No resource found that matches the given name (at 'resource' with value '@drawable/notification_icon

christianguevara commented 5 years ago

Can you check if the resources were successfully copied to the android resources folders? Because if it's not found, then it's not been copied.

Edit: Remember, the original resources must be in resources/android/notification_icon/drawable-xxx/notification_icon.png that's the cordova project folder as stated in the src attribute of the XML copied.

ChristianVega5421 commented 5 years ago

In the config.xml i'm using this for android:

<resource-file src="resources/android/notification_icon/drawable-mdpi/notification_icon.png" target="app/src/main/res/drawable-mdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-hdpi/notification_icon.png" target="app/src/main/res/drawable-hdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xhdpi/notification_icon.png" target="app/src/main/res/drawable-xhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxxhdpi/notification_icon.png" />
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
</config-file>
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:value="@color/accent" />
</config-file>

It does copy the resources in resources/android/notification_icon/drawable-***/notification_icon.png to the android respective folders and references them later in the manifest, i tested this and it works, maybe try it.

The icons are generated in here

But this will set the default notification icon and when the method that creates the notification is called It will just use it as Small Icon and will not set it as Large Icon,can you show me an example of notification with Small and Large icon?

conormag commented 5 years ago

@rhanesoghlyan that would suggest you haven't got the icon resources in a location matching the src parameter like in the example above. The src location is relative to the cordova folder.

christianguevara commented 5 years ago

In the config.xml i'm using this for android:

<resource-file src="resources/android/notification_icon/drawable-mdpi/notification_icon.png" target="app/src/main/res/drawable-mdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-hdpi/notification_icon.png" target="app/src/main/res/drawable-hdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xhdpi/notification_icon.png" target="app/src/main/res/drawable-xhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxhdpi/notification_icon.png" />
<resource-file src="resources/android/notification_icon/drawable-xxxhdpi/notification_icon.png" target="app/src/main/res/drawable-xxxhdpi/notification_icon.png" />
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
</config-file>
<config-file parent="/manifest/application" target="app/src/main/AndroidManifest.xml">
  <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:value="@color/accent" />
</config-file>

It does copy the resources in resources/android/notification_icon/drawable-***/notification_icon.png to the android respective folders and references them later in the manifest, i tested this and it works, maybe try it. The icons are generated in here

But this will set the default notification icon and when the method that creates the notification is called It will just use it as Small Icon and will not set it as Large Icon,can you show me an example of notification with Small and Large icon?

Right, for the larger icon i'm almost sure a small code modification is needed in the lib, so if the icon exists it will show it.

evinkuraga commented 5 years ago

I also can't get a different icon to show up for the life of me. Has anyone gotten this to work? And if so, can you break it down as much as possible?

For instance:

  1. create icon set from link mentioned by @christianguevara
  2. Put the "drawable-xxxx" FOLDERS inside the /res/icon/android/ directory
  3. Copy the code mentioned by @christianguevara in your config.xml
  4. Change the paths in this above code to : res/icon/android/drawable-xxxx/ICON_NAME.png
  5. In the config, replace the @drawable/notification_icon with @drawable/YOURICON.png

Also, if anyone could clarify how this is different from the cordova element. Does this need to tbe removed for the system tray icon to show?

@steeper ever found how to get this to work?

conormag commented 5 years ago

Here, I have put my files in a folder call res in my cordova root. You can see the corresponding lines in my config.xml on the right.

screen shot 2018-11-02 at 17 45 22

now, as a result this is where the files get copied at build time and baked into the build

screen shot 2018-11-02 at 17 47 08