4

I have added firebase notification in my app . When app is running i get notification icon but when my app is in background or closed than notification icon doesn't show . Eiher it is small icon or large .

i have done many solution from Stackoverflow but all failed.

NotificationCompat.Builder builder = new  NotificationCompat.Builder(this, channelId)

            .setAutoCancel(true)
            .setSound(sound)

            .setColor(ContextCompat.getColor(this, R.color.colorGivelife))
            .setContentTitle(remoteMessage.getNotification().getTitle())
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(),
                    R.drawable.logo))
            .setContentText(remoteMessage.getNotification().getBody()).setAutoCancel(true).setContentIntent(pendingIntent);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setSmallIcon(R.drawable.white_logo);
        builder.setColor(getResources().getColor(R.color.colorGivelife));
    } else {
        builder.setSmallIcon(R.drawable.logo);
    }

I can get notification icon when app is in background.

Muntasir Aonik
  • 1,800
  • 1
  • 9
  • 22

1 Answers1

2

Use this tag and put it in your Manifest. For me this worked. Hope it works for you.

<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_app_icon" />
Muntasir Aonik
  • 1,800
  • 1
  • 9
  • 22