1

I'm stuck on setting notification icon for my app. In my code I have both this:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.ic_stat_ic_notification)).....

and this:

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

So, when the app is open works correctly, I see the drawable image. But, when the app is in background or closed, I see a blank image. I suppose that this blank image is the gray version of my app icon.

Is it correctly? How can I set any image for the notification in case of the app is in background?

EDIT

How the notification appears:

https://imgur.com/a/d1T37

halfer
  • 18,701
  • 13
  • 79
  • 158
lucacatr
  • 91
  • 2
  • 11
  • Have a look at their documentation. It might help you. https://firebase.google.com/docs/cloud-messaging/android/receive – Ruchira Randana Oct 14 '17 at 16:29
  • @ruch ehm..I read all on Google Firebase website...and I'm here because I didn't find enough information – lucacatr Oct 14 '17 at 17:33
  • Possible duplicate of [Icon not displaying in notification: white square shown instead](https://stackoverflow.com/questions/30795431/icon-not-displaying-in-notification-white-square-shown-instead) – nomag Oct 14 '17 at 17:47
  • @lucacatr: Please take in mind that everyone is trying to help you. You may have read the docs, but you haven't specifically mentioned that. Many new people post on SO when they need help, but there are many instances where they haven't attended to the doc itself. That's why I did. Adding more, your tone doesn't seem to be the best in a forum like SO. – Ruchira Randana Oct 14 '17 at 18:05
  • @Ruchira: I agree that it's important for readers to be able to understand what steps have been taken to solve a problem. However, we don't want to encourage question authors merely to say "I have read the docs" or "I have tried lots of things" since those assurances in themselves are not specific or useful, and they become a standard boilerplate that might be added by people who in reality have not read any docs at all. – halfer Oct 20 '17 at 18:32
  • Regarding "tone", it's worth considering that most people are amenable in real life, and a friendly/earnest tone just does not carry well in short comments. It is probably just best not to mention that sort of thing, and instead flag a comment if you think it violates [the 'be nice' policy](https://stackoverflow.com/help/be-nice). – halfer Oct 20 '17 at 18:34
  • 1
    Hi @halfer. Thank you for your advice. I agree with you on that certain short comments might not reflect well as it would have in the real world. I wasn't aware of the "be nice policy" before. I'll definitely flag from now onwards. Cheers! – Ruchira Randana Oct 21 '17 at 16:49

1 Answers1

3
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_logo)
            .setContentTitle(title.toString())
            .setSound(defaultSoundUri)
            .setPriority(Notification.PRIORITY_MAX)
            .setContentText(sp.toString());

Try using this, icon_logo is the icon image in the drawable.

neo73
  • 354
  • 6
  • 19