Blueriver Blueriver - 1 year ago 236
Android Question

Icon not displaying in notification: white square shown instead

My app generates a notification, but the icon I set for that notification is not being displayed. Instead I get a white square.

I have tried resizing the png of the icon (dimensions 720x720, 66x66, 44x44, 22x22). Curiously, when using smaller dimensions the white square is smaller.

I have googled this problem, as well as the correct way of generating notifications, and from what I've read my code should be correct. Sadly things are not as they should be.

My phone is a Nexus 5 with Android 5.1.1. Problem is also present on emulators, a Samsung Galaxy s4 with Android 5.0.1 and a Motorola Moto G with Android 5.0.1 (both of which I borrowed, and don't have right now)

Code for notifications follows, and two screenshots. If you require more information, please feel free to ask for it.

Thank you all.

@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification;
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
notification = new Notification.Builder(this)
.setStyle(new Notification.BigTextStyle().bigText(msg))
notificationManager.notify(0, notification);

without opening the notification
notifications opened

Answer Source

Cause: For 5.0 Lollipop "Notification icons must be entirely white".

If you want to support Lollipop Material Icons then make transparent icons for Lollipop and above version. Please refer following

Implementation of Notification Builder for below and above Lollipop OS version would be:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
} else { 

If you want to set colored single icon for all OS version then

Solution: For colored icons, use

defaultConfig {
        applicationId ""
        minSdkVersion xx
        targetSdkVersion 20 // < 21 (target sdk version in manifest file will be less than 21).
        versionCode x
        versionName "x.x"

in app/build.gradle file. It will solve your problem completely!!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download