react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

grey square as icon notification android

Open manuTro opened this issue 7 years ago • 33 comments

Hi! android_bug my notification works fine on android and ios but in some android devices (motorola) instead of my app icon appear a grey square.. How I can fix it?

Thx

manuTro avatar Apr 30 '18 12:04 manuTro

Same problem here. How can we fix it?

fbazzana avatar May 07 '18 20:05 fbazzana

This is probably related to #177

To fix this, you'll have to move the notification icon from the drawable folders to the mipmap folders. Hope this will help you.

wuppious avatar May 14 '18 16:05 wuppious

You need to:

  • Create an asset that only uses white pixels, on a transparent background. It's important to not use any colour other than white.
  • Your asset must be called ic_notification.png
  • Your assets must be placed inside mipmap-* directories and not drawable-* (as @wuppious mentioned).

Your asset dimensions (in pixels): mipmap-mdpi - 24x24 mipmap-hdpi - 36x36 mipmap-xhdpi - 48x48 mipmap-xxhdpi - 72x72 mipmap-xxxhdpi - 96x96

hannigand avatar May 16 '18 14:05 hannigand

Looks like @wuppious was correct in having them in both folders as that seems to have solved my issue for notification icon images in android builds before 5.0 (Lollipop). Unfortunately though now android phones with version 5.0 (Lollipop) and higher now display a grey notification icon which is where @hannigand your suggestion works. Although I still needed them in the mipmap folder to get them so show up properly which is odd.

Has anyone found a solution for swapping icons based on the android version? I'm also noticing that even though I have the transparent ic_notification.png in both folders my app still ignores those files and uses the ic_launcher.png files instead.

Any further suggestions?

Diego-F-Aguirre avatar Jun 22 '18 16:06 Diego-F-Aguirre

My suggestion was to move the icons from drawable to mipmap, not include them in both directories. I have my icons working on all versions, so maybe having them in both folders breaks it for you?

wuppious avatar Jun 22 '18 16:06 wuppious

Ah I misread my apologies. So I did as you suggest @wuppious but even though my ic_notification file is white on transparent the app uses the ic_launcher file instead of the ic_notification icon.

Making the ic_launcher file white on transparent png works but obviously that breaks my actual app icon, plus that's not the functionality I want as I want the ic_launcher image to have color.

Diego-F-Aguirre avatar Jun 22 '18 16:06 Diego-F-Aguirre

Looking at my own projects, I can safely say it shouldn't be an issue, since I have the icon in both folders. Would you mind sharing the code that creates the notification?

wuppious avatar Jun 22 '18 17:06 wuppious

@wuppious, ok so just tested on two physical phones. They both default to using the ic_launcher as their notification icon but phones with version 7.0 actually displays the ic_launcher icon with color while phones with android version 8.0 display a grey icon.

    onNotification = (notification) => {
        if (!(notification && notification.data && (Toast && Toast.display && Toast.handle))) {
            return;
        }

        if (notification.data && notification.data.conversation_id) {
            const conversationId = notification.data.conversation_id;
            // See app/_shared/containers/toastContainer for an explanation of why we pass in an onPress object.
            this.getOnPress({ conversationId: conversationId })
                .then((onPress) => {
                    if (notification.foreground) {
                        Toast.display({
                            type: 'message',
                            props: {
                                avatarUrl: notification.data.avatar_url,
                                displayName: notification.data.display_name,
                                messageBody: notification.data.message,
                                messageType: _.startCase(notification.data.message_type)
                            },
                            ...onPress,
                            duration: 5000,
                            delay: 1000
                        });
                    } else if (onPress) {
                        Toast.handle(onPress);
                    }
                });
        } else if (notification.data && notification.data.screen) {
            const screen = notification.data.screen;
            const objectKey = notification.data.objectKey;
            const objectId = notification.data.objectId && parseInt(notification.data.objectId);
            const params = objectId && objectKey ? { [objectKey]: objectId } : null;
            const onPress = { onPress: { routeName: screen, params: params } };

            Toast.handle(onPress);
        } else {
            this.props.refresh();
        }
    }

Diego-F-Aguirre avatar Jun 22 '18 17:06 Diego-F-Aguirre

And this is the code I'm using to initialize my notifications.

    initNotifications = () => {
        return new Promise(() => {
            PushNotification.configure({
                onRegister: (token) => {
                    this.postDeviceToken(token);
                    PushNotification.popInitialNotification((notification) => {
                        if (notification) { this.onNotification(notification); }
                    });
                },
                onNotification: (pushData) => {
                    this.onNotification(pushData);
                },
                senderID: config.fcmSenderId,
                popInitialNotification: true,
                requestPermissions: true
            });

            api.storage.set('@NotificationsEnabled', 'true');
            this.props.dispatch(setNotificationsAreEnabled(true));
            if (this.props.onRegisterCallback) {
                this.props.onRegisterCallback();
            } else {
                return;
            }
        });
    };

Diego-F-Aguirre avatar Jun 22 '18 17:06 Diego-F-Aguirre

Do you use this library for local notifications? When creating/scheduling a notification, you can specify the icon being used (smallIcon) to match the icon image. I can't really see why your icon isn't working, but for whatever reason it is defaulting to the ic_launcher. Maybe setting it explicitly to use ic_notification would help. Other than that I'm out of ideas.

wuppious avatar Jun 22 '18 18:06 wuppious

Unfortunately no, I'm using it for remote notifications only at the moment. I'll keep on digging though, thanks for the help!

Diego-F-Aguirre avatar Jun 22 '18 19:06 Diego-F-Aguirre

@Diego-F-Aguirre Have you found a solution? I am experiencing the same issue when receiving remote notifications (local notifications display the right icon)

akbokha avatar Jul 22 '18 16:07 akbokha

I'm experiencing the same issue as @akbokha

Local notifications show my proper icon, remote notifications are not. I've tried almost every combination of icon placement in drawable and mipmap, and also setting the smallIcon field on the remote notification, all to no avail.

@Gp2mv3, any tips here?

illestrater avatar Aug 02 '18 04:08 illestrater

@hannigand 's suggestion solved it for me. (Moving the icons to the mipmap folders and calling them ic_notification.png)

This should probably be in the documentation somewhere if it isn't already.

dgurns avatar Sep 21 '18 21:09 dgurns

@hannigand thank you. I replaced icons and after reinstall an app it works!

vitalyliber avatar Oct 16 '18 10:10 vitalyliber

I've fixed it on my app by ensuring

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

using the image name 'ic_notification.png'

and also ensuring your GCM data has this property:

icon: 'ic_notification'

illestrater avatar Oct 22 '18 09:10 illestrater

You have to follow some rules for notification icon link. First, generate notification icons link of all sizes. and put the icon name ic_notification. Then use put all sizes ic_notification in respective folder in resource mipmap folder and add line in AndroidManifest.xml file. <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_notification" />

rahulworld avatar Apr 23 '19 13:04 rahulworld

What are the rules you have to follow exactly for the notifications icon? The link you supplied is just general info for all icons re: Material Design.

bobber205 avatar Apr 29 '19 20:04 bobber205

Hi @bobber205, Yes, Make sure notification icon is of the PNG file format with a transparent background. Thanks

rahulworld avatar Apr 30 '19 13:04 rahulworld

still not working :/

adityamohta avatar Jul 25 '19 09:07 adityamohta

My case was a little bit contra intuitive. I assumed the default_notification_icon would also work for the local background notifications but it doesn't.

The default notification icon defined in AndroidManifest.xml is used when no icon is set for incoming notification messages. Incoming, as far as I understand only stand for the remote push notifications, not the local scheduled background notifications.

In our case we had to add Android specific call to the notification.setSmallIcon('ic_notification').

Example:

  const notification = new firebase.notifications.Notification()
    .android.setChannelId('...')
    .android.setSmallIcon('ic_notification')

If you named your icon differently than ic_notification, change the string according for your case.

Hope it helps someone else.

attitude avatar Aug 15 '19 16:08 attitude

So I've been using the wix react-native-notifications library to display my notifications. Turns out they chose to write custom code to completely override whatever you set in your metadata!

I discovered this by searching for Notification.Builder in the whole project. There is a piece of code that looks explicitly for a file in drawable/ called notification_icon.

So the solution is to create 1 icon which is transparent + white color and put it in as drawable/notification_icon.png

I can't believe somebody would write a confusing piece of code like this but that's the horrors of open source for you :/

LPitonakova avatar Jun 09 '20 19:06 LPitonakova

I flowed the orientation of @hannigand and I could fix the grey square.

But now I have a blue small icon in my notification. In the status bar the icon is white.

Does someone know how to set the color of the small icon in the notification?

I have in my Manisfest:

<meta-data android:name="com.dieam.reactnativepushnotification.notification_color" android:resource="@android:color/white"/>

My icon is a white logo with a background transparent and I have inside mipmap folder with ic_notification.png name.

allinelara avatar Jul 03 '20 14:07 allinelara

for the record, the color has to be defined in: android/app/src/main/res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="myBlue">#1B457E</color>
</resources>

Then the icon will be colored with the myBlue color. Hope it helps someone.

github4es avatar Aug 04 '20 22:08 github4es

Try this one. It worked for me....... https://clevertap.com/blog/fixing-notification-icon-for-android-lollipop-and-above/

Nsingh0007 avatar Sep 04 '20 04:09 Nsingh0007

for react-native user, like @hannigand said , ic_launcher.png or ic_notification.png should be in this path :

android/app/src/main/res/mipmap-*

magixus avatar Sep 25 '20 14:09 magixus

I also had this grey square for a vector notification icon - not .png, but .xml - but the type might not be important for what i found:

The reason in my case was, that i needed to change the NotificationImportance to play no sound when notifying and therefore i needed to use a new notification channel. But now on the new channel the icon did not work any more....

After some trial and error i found out, that actually the name of the icon was the problem - i seems to be occupied forever for the old channel i used earlier. So after renaming my notification icon and setting the renamed one to the new channel it finally worked again. Maybe that helps somebody...

matt-uib avatar Oct 15 '20 13:10 matt-uib

You need to:

  • Create an asset that only uses white pixels, on a transparent background. It's important to not use any colour other than white.
  • Your asset must be called ic_notification.png
  • Your assets must be placed inside mipmap-* directories and not drawable-* (as @wuppious mentioned).

Your asset dimensions (in pixels): mipmap-mdpi - 24x24 mipmap-hdpi - 36x36 mipmap-xhdpi - 48x48 mipmap-xxhdpi - 72x72 mipmap-xxxhdpi - 96x96

This was the only thing that made it to work. By default, when you create the ic_notifications using the Android Studio Image Asset, it create the images as 'drawable' but instead you need to change them to 'mipmap' as mention above.

xesf avatar Oct 30 '20 16:10 xesf

You need to:

  • Create an asset that only uses white pixels, on a transparent background. It's important to not use any colour other than white.
  • Your asset must be called ic_notification.png
  • Your assets must be placed inside mipmap-* directories and not drawable-* (as @wuppious mentioned).

Your asset dimensions (in pixels): mipmap-mdpi - 24x24 mipmap-hdpi - 36x36 mipmap-xhdpi - 48x48 mipmap-xxhdpi - 72x72 mipmap-xxxhdpi - 96x96

Thank you a lot, the notification name make it work for me (i call it notifications- did not work at start), blass you !!!

jeffreybenabou avatar Oct 23 '21 07:10 jeffreybenabou

Even if your not using firebase messaging you still need to add a resource file so that it gets included in the apk.

<application>
      ...
      <meta-data android:name="some-random-name" android:resource="@mipmap/ic_notification" />

FelixMo42 avatar Apr 27 '22 19:04 FelixMo42