0

I encountered an issue sending notifications in my Android app. I am setting my custom icon via .setSmallIcon(R.drawable.ic_bublic_2) but android ignores it and shows a default launcher icon instead. Here is my code:

private fun publishNotification(title: String, body: String) {
    val intent=Intent(this, MainActivity::class.java)

    val pendingIntent = TaskStackBuilder.create(this).run {
        addNextIntentWithParentStack(intent)
        getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
    }

    val notif = NotificationCompat.Builder(this,CHANNEL_ID)
        .setContentTitle(title)
        .setContentText(body)
        .setSmallIcon(R.drawable.ic_bublic_2)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setContentIntent(pendingIntent)
        .build()

    val notifManger = NotificationManagerCompat.from(this)

    if (ActivityCompat.checkSelfPermission(
            this,
            Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED
    ) {
        notifManger.notify(DEFAULT_NOTIF_ID, notif)
    }
}

and here is a screenshot to be more clear: enter image description here

Edit 1:

setting .setLargeIcon(largeIconBitmap) solve problem for icon on notification but the status bar icon remains the same launcher icon.

enter image description here

enter image description here

1
  • Assuming this is a Xiaomi device (or similar), have you tried using the "Android-style" notification setting? Commented Nov 17 at 4:57

1 Answer 1

1

Small icon is for the icon in the status bar

Set the small icon, which will be used to represent the notification in the status bar and content view (unless overridden there by a large icon)

you want setLargeIcon which is the notification content

Add a large icon to the notification content view

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it was useful, though status bar icon is also the same launcher icon.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.