1

I have implemented Fcm push notification , message receive successfully but the problem is that when app is in background and if i got notification can't get app icon, it display as white square

i have tried below code because app is in background it get icon from menifest

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

also observed that change targetSdkVersion 23 to targetSdkVersion 19 its working well but the problem is that when changed targetSdkVersion 19 i am not getting marshmallow run time permission dialogue

Need help Note that problem is occured when app is in background See the image

  • Possible duplicate of [Notification Icon with the new Firebase Cloud Messaging system](https://stackoverflow.com/questions/37325051/notification-icon-with-the-new-firebase-cloud-messaging-system) – Omkar Jun 09 '17 at 07:22
  • i have only problem to get icon when app is in background – Regular cash recharge Jun 09 '17 at 07:33

1 Answers1

2

This problem is a combination of two problems basically:

1) For lollipop above devices, you have to set silhouette icon, for this check this answer Link to set notification icon on lollipop and above devices

2) When you are working with FCM, notification messages are delivered to your onMessageReceived callback only when your app is in the foreground(most probably you would be setting your notification to show user after you received push message in onMessageReceived), if it is not (so it's in the background, or closed entirely), FCM handles showing the notification for you and onMessageReceived not called, so even after handling silhouette icon condition for lollipop and above devices, notification icon not showing, because your code not getting call in this case.

So, finally, to solve this FCM problem, add this code in your manifest file.

<meta-data
    android:name="com.google.firebase.messaging.default_notification_icon"
    android:resource="@drawable/ic_notification_icon"/>
<meta-data
    android:name="com.google.firebase.messaging.default_notification_color"
    android:resource="@color/color_of_your_desire"/>
shaby
  • 1,301
  • 1
  • 15
  • 17