1

I know that to support Lollipop Material design guidelines we have to make notification icon as transparent.

Here is my FCM onMessageReceived() function to show noticication.

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    NotificationCompat.Builder mBuilder;
    mBuilder =   new NotificationCompat.Builder(this)
            .setContentTitle(remoteMessage.getNotification().getBody()) // title for notification
            .setContentText(remoteMessage.getNotification().getTitle()) // message for notification
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND)
            .setSmallIcon(getNotificationIcon())
            .setAutoCancel(true); // clear notification after click

    Intent intent = new Intent(this, CheckInListPage.class);
    PendingIntent pi = PendingIntent.getActivity(this,0,intent,Intent.FLAG_ACTIVITY_NEW_TASK);
    mBuilder.setContentIntent(pi);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP);
    return useWhiteIcon ? R.drawable.logo_a_transparent : R.drawable.logo_notifc;
}

But here my issue is that when the application is running in foreground and visible, it will take my logo_a_transparent and will get desired result (screenshot - first icon in the notification bar).

But when we are pausing the application and an FCM push came, It takes my app icon (android:icon="@drawable/ic_launcher") as notification icon became white (screenshot - second icon in the notification bar).

Replacing app icon as transparent will work, But not a correct solution.

Two notification icon are from the same application. The first icon is the push notification when application is foreground and other is when application background

Ebin Joy
  • 2,690
  • 5
  • 26
  • 39
  • 1
    because you are using GetNotification() insteam use getData() method to call onmessageReceived every time, and you can same icon – Divyesh Patel Apr 19 '17 at 10:20
  • See here:http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop –  Apr 19 '17 at 10:37
  • I have already done that... But when we are pausing the application and an FCM push came, notification icon became white (screenshot - second icon in the notification bar). When application foreground, there are no issues. – Ebin Joy Apr 19 '17 at 10:40
  • Check this http://stackoverflow.com/a/39142981/1939564 – Muhammad Babar Apr 19 '17 at 12:04
  • Its just give a colour but issue not fixed yet. The problem is when app is paused fcm push notification use app icon rather than my transparent icon. This can be solved by making app icon as transparent but this is not comfort for app icon. – Ebin Joy Apr 19 '17 at 12:58
  • Thanks @DivyeshPatel for the idea. – Ebin Joy Apr 20 '17 at 07:24

3 Answers3

0

Add this line in your menifestfile set your resource as your choice add this one

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

<meta-data
        android:name="com.google.firebase.messaging.default_notification_color"
        android:resource="@android:color/transparent" />
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31
  • I have added But not working – Ebin Joy Apr 19 '17 at 10:25
  • add second meta data and try...may be hope this one is help for you – Ratilal Chopda Apr 19 '17 at 10:32
  • Still not working... my fcm version is compile 'com.google.firebase:firebase-messaging:9.6.1' – Ebin Joy Apr 19 '17 at 10:36
  • Try Changing this line compile 'com.google.firebase:firebase-messaging:10.2.1' – Ratilal Chopda Apr 19 '17 at 10:40
  • I have tried that also, but unfortunately its not working. Suppose if it is working but even though it will not be a complete solution because in the case of pre-lollipop device we want coloured icon rather than a transparent icon. so we want set icon based on condition rather than simply setting an icon. – Ebin Joy Apr 19 '17 at 10:54
0

With FCM, you can send two types of messages to clients applicatin

1) Notification messages, 2) Data messages Here fcm doumentation

Notification Message calls onMessageReceived() only when the application is foreground. Notification messages are delivered to the notification tray when the app is in the background that's automatically handled by Android system rather than calling onMessageReceived(), The system uses app icon as notification icon that's why icon became white in background push. The android application needs not to be transparent.

In the case of Data Message whether the app is in the background or the foreground it will always be handled by onMessageReceived().

Data Message

  {  "to" : "Ahd8fsdfu78sd...", "data" : {
     "Name" : "...",
     "body" : "...",
    }
}

So I should use a data-only message payload or Messages with both notification and data payloads, so my onMessageReceived() can handle this and correct notification icon will displayed.

Ebin Joy
  • 2,690
  • 5
  • 26
  • 39
0

Fix at firebase 12.0.0. Just update your build.gradle to 12.0.0

https://firebase.google.com/support/release-notes/android#20180320

JackWu
  • 1,036
  • 1
  • 12
  • 22