8

I am using FCM in my android app to manage push notification. Its completely working fine when the app is in foreground and the app icon is also visible(properly). But when the app is running in background I am not getting the notification properly. Instead of the transparent icon its showing the white square icon as the notification icon. I know that, FCM will automatically handle the background operation. But I need to show my app icon instead of that white icon. Note: I am using transparent icon only. I also tried the below coding

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

But none of the solutions actually worked for me. Can someone tell me what to do?

Encipherer
  • 411
  • 7
  • 23
  • U might be testing on 5.0 or above.. right? if so then ceck this out http://stackoverflow.com/questions/28387602/notification-bar-icon-turns-white-in-android-5-lollipop – Adeel Turk Nov 23 '16 at 09:51
  • Thanks for the reply. I tried this solution but its not working for me. – Encipherer Nov 24 '16 at 13:42
  • my pleasure :) try this and tell me what happens notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_app_sky)); – Adeel Turk Nov 25 '16 at 06:40

2 Answers2

2
{
 "to" : "token",
  "notification": {"body": "Body",
"title": "Title",
"click_action": "com.sample.test.OPEN_ACTIVITY",
      "icon" : "ic_launcher"
},
 "data": {
    "image": "https://ibin.co/2t1lLdpfS06F.png",
    "message": "Firebase Push Message Using API"

  }
 }

So if the name of "icon" is the same as your file name in app drawable, FCM takes care of result, if your app is in background. In foreground its your own custom implementation of notification, which will work. Just leme know if, that solved the problem.

Denny Mathew
  • 842
  • 3
  • 13
  • 31
  • worked for me - but I would really like to know how to do this in app's code and not relay on matching name for the icon file – Yoav R. Dec 08 '17 at 01:24
0

I faced this problem before and solved it like that:

private int getNotificationIcon() {
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.LOLLIPOP);
    // LOLLIPOP or Marshmellew>>>>>>>>>>>>>>>>>>>>> KitKat or Less
    return useWhiteIcon ? R.drawable.logo_new : R.drawable.logo;
}

and just call this function in setSmallIcon()

nbuilder.setSmallIcon(getNotificationIcon());
Malik Abu Qaoud
  • 208
  • 1
  • 9