Search code examples
javaandroidandroid-notificationsforeground-service

Notification not have icon when defining as `setSmallIcon(R.mipmap.ic_launcher)` for ForegroundService


I am building Notification for my ForegroundService on Android, but my icon is not showing:

return new NotificationCompat.Builder(this, CHANNEL_ID)
                .setContentText("Sdílení polohy je aktivní")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.ic_launcher))
                .build();

enter image description here

What am I doing wrong?


Solution

  • Create an icon set that only uses white color and put the mipmap folders, on a transparent background.You do not use any color other than white. Icon generator

    And use this code for icon tint:

     .setSmallIcon(R.mipmap.notification_icon)
     .setColor(ContextCompat.getColor(context, R.color.yourColor))