I am setting large icon for push notification by using following code.
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.logo)
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setColor(getResources().getColor(R.color.green))
.setSound(defaultSoundUri)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logo))
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntent);
This works fine and shows largeIcon
when app is in foreground, but when app is not in foreground, it does not display large icon.
I am testing the app in samsung s7(oreo)
The code snipped you posted works fine only when your app is in the foreground because it only gets called when the app is in the foreground. When the application is in the background, the Android system displays the notification for you (based on the 'notification' object in the JSON object that the server sends to the device). Your receiver is not being called at all. Currently, Firebase Cloud Messaging doesn't support setting a large icon as a payload in the request.
A way around this is to not include a 'notification' object in the POST payload of the message. When you only include 'data' object in the payload, your receiver will be asked to handle the notification even when your application is in the background. Then, you can build the notification the same way as if the app was in the foreground and set a large icon for the notification.
Take a look at this answer for a more detailed explanation about this issue.
Try this,
you're recommended to set default values to customize the appearance of notifications. You can specify a custom default icon and a custom default color that are applied whenever equivalent values are not set in the notification payload.
Add these lines inside the application tag to set the custom default icon and custom color:
<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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With