0

I'm trying to build my own notification as soon as I receive a payload from my server in my FCM Receiver, I set my notification icon to my app icon which is in PNG Format, however, my notification is displayed with a white square instead and I don't know why.. Here's my code:

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.icon)
                .setContentTitle("Your chat is going to expire tomorrow!");

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, main_activity.class);

        resultIntent.putExtra("launchedFromNotification",true);

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your app to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(main_activity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );

        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        // mNotificationId is a unique integer your app uses to identify the
        mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108
Ahmed Khairy
  • 105
  • 1
  • 12
  • Hello Ahmed Khairy, I've been desperate like you looking a solution for this and I found this post where if you do exactly what it says the problem with the icon is gone. I was targetting Android O Device and the app with SDK (27), all works now. https://stackoverflow.com/a/48562435/3438335 – Ivor Feb 26 '18 at 13:24

1 Answers1

1

This usually happens when you use a non-alpha icon

When you use icons on your notification, android paints over all non-alpha (non-transparent) parts of the icon. This means if you use a square image as your notification icon, it would just come out as a white square.

To fix this, just use a shape-like icon. Check below for reference:

Icon Reference

Ace Falobi
  • 661
  • 1
  • 7
  • 23