0

I know that from Lollipop there are some design level changes for the icon of notification that's why notification icon is white above lollipop release.

But there are requirement for me to show the exact app icon for the notification, is it possible or not?

There are some apps that are showing the same app icon in notification, on the lollipop and above platform.

AL.
  • 36,815
  • 10
  • 142
  • 281
Santosh Yadav
  • 338
  • 2
  • 4
  • 15
  • They might use the `setContent(contentView)` method in order to achieve that, see here for details: http://stackoverflow.com/questions/18367631/change-notification-layout – Daniel Nugent Jan 12 '17 at 18:04

3 Answers3

3

you can set white icon above lolipop using this method.

  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) 
  {
        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
        mBuliderREC.setLargeIcon(icon);
        mBuliderREC.setSmallIcon(R.drawable.notification_icon);
  } else {
               mBuliderREC.setSmallIcon(R.drawable.ic_launcher);
         }
Sachin Suthar
  • 692
  • 10
  • 28
0

Same problem, I have faced in one of My project but I solved with below code. Please check It might help you

private void sendNotification(String message) {
        int NOTIFICATION_ID = (int) Calendar.getInstance().getTimeInMillis();
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.loading_icon)
                .setContentTitle(getString(R.string.app_name))
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
                .setContentText(message);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
        Intent resultIntent = new Intent(this, HomeActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        mBuilder.setAutoCancel(true);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
samsad
  • 1,241
  • 1
  • 10
  • 15
  • Please explain how the answer helps to make the notification icon **not** appear as white. – K Neeraj Lal Jan 12 '17 at 18:25
  • Actually, I am using color code(Related to app colour) to fill circle and placing app icon in center (That will be automatically in center). Try above code It will work. – samsad Jan 12 '17 at 18:31
0

You can show any image in notification by adding parameter "image" while sending parameter.

Using FCM with image is assets folder:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"www/images/test_image.png"},"priority":"high"}

Using FCM with image in drawable folder:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"ic_icon"},"priority":"high"}

Using FCM with image from external link:

{"to":"[add your token]","notification":{"title":"[add title]","body":"[add your message]","image":"http://www.test.com/test_img.png"},"priority":"high"}

Using GCM with image in assets folder:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"www/images/test_img.png"}}

Using GCM with image in drawable folder:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"ic_icon"}}

Using GCM with image from external link:

{"registration_ids": ["[please dont change]" ],"data": {"tickerText":"example test GCM","contentTitle":"content title GCM","message": "Enter your message","title":"GILAC","image":"http://www.test.com/test_img.png"}}

Note: Notification icon/image must be png image.

Krunal
  • 317
  • 1
  • 7
  • Actually problem is that i am unable to handle the onMessageReceived() method of FCM push notification, when app is in background. so without getting the call to that method It seems impossible to set the icon of notification as suggested by you. – Santosh Yadav Jan 17 '17 at 05:40