Search code examples
androidpush-notificationstatusbarandroid-notificationsandroid-notification-bar

Android notifications different icon for status bar and notification body


I have a notification of battery level. I want to make different icon in status bar and notifications center. In status bar: number (2 digits). In body: my app icon. How can I do that? The app icon is also in the status bar, how can I change that?


Solution

  • I'm not sure what your code looks like right now but I'd do something like this:

    Notification.Builder nb = new Notification.Builder(context)
    .setContentTitle("title")
    .setContentText("content")
    .setAutoCancel(true)
    .setLargeIcon(R.drawable.large_icon)
    .setSmallIcon(R.drawable.small_icon)
    .setTicker("ticker text");
    NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(100, nb.build());
    

    Note the setLargeIcon() and setSmallIcon(). The icon you want to show in the 'ticker' should be set in setSmallIcon() and for what you have called the 'notification centre', you should use setLargeIcon(). That should work.