react-native-notifications icon indicating copy to clipboard operation
react-native-notifications copied to clipboard

I cannot set the default icon of the push notifications in AndroidManifest.xml.

Open DivinoMatheus opened this issue 6 years ago • 11 comments

First I added the following in AndroidManifest.xml

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />

I generated all icons in this platform and put them in the drawable folders.

But the default icon in the app continues that gray square icon.

Please, someone can help me? 432b963a-37f7-4c57-8144-0928076638ae

Please, someone can help me?

I'm using the following icons in the drawable folders: ic_stat_ic_notification.zip

DivinoMatheus avatar Mar 13 '20 18:03 DivinoMatheus

My suggestion: Use android studio to generate your notification icon. Right click on 'res' folder -> New -> Image Asset From what I've tried, it seems that the name of the image must be notification_icon

After that, edit your AndroidManifest.xml accordingly here.

I have attached some screenshots to help navigate in Android Studio. generating image asset configuring image asset

tingzhouu avatar Mar 20 '20 03:03 tingzhouu

Hi @tingzhouu I followed your step, but still see the square icon. image What should I do now?

Great-hijack avatar Apr 08 '20 16:04 Great-hijack

I found solution. Should name notification icon name to "notification_icon" according to the source code.(lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java) int iconResId = getAppResourceId("notification_icon", "drawable"); But if we can set icon via postLocalNotification() function, it will be more helpful.

Anyway Thank you all.

Great-hijack avatar Apr 08 '20 18:04 Great-hijack

I did the same. Change name to notification_icon and added in drawable but no luck.

theromie avatar May 08 '20 13:05 theromie

@theromie

  1. please check the following code is in AndroidManifest.xml
<meta-data
      android:name="com.google.firebase.messaging.default_notification_icon"
      android:resource="@drawable/notification_icon" />
  1. follow this comment https://github.com/wix/react-native-notifications/issues/533#issuecomment-601513113

Hope it would be helpful

Great-hijack avatar May 08 '20 13:05 Great-hijack

@Great-hijack Thanks, It works after creating image from Android Studio

theromie avatar May 08 '20 13:05 theromie

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jun 07 '20 14:06 stale[bot]

The issue has been closed for inactivity.

stale[bot] avatar Jun 14 '20 14:06 stale[bot]

I guess this should be add to documentation:

Setting the icon and color:

Drawable folder: Add your notification icon named as notification_icon.png

colors.xml <color name="colorAccent">Your color hex here</color>

AndroidManifest:

<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorAccent" />

jrrcdev avatar Aug 19 '20 11:08 jrrcdev

After 2 hours of trying all sorts of places to put and reference the notification icon, I would strongly be in favor of putting this to the docs

danielwinkler avatar Sep 30 '20 20:09 danielwinkler

For anyone not willing to modify their code, here is a small adaptable patch in the meantime

diff --git a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
index ac04274..8a59fb2 100644
--- a/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
+++ b/node_modules/react-native-notifications/lib/android/app/src/main/java/com/wix/reactnativenotifications/core/notification/PushNotification.java
@@ -166,7 +166,7 @@ public class PushNotification implements IPushNotification {
     }

     private void setUpIcon(Notification.Builder notification) {
-        int iconResId = getAppResourceId("notification_icon", "drawable");
+        int iconResId = getAppResourceId("ic_notification", "mipmap");
         if (iconResId != 0) {
             notification.setSmallIcon(iconResId);
         } else {

Andarius avatar Jul 25 '23 08:07 Andarius