0

I already set my notification icon but its showing mipmap ic_launcher icon.Plese help me to show the icon when notification comes.

 private void addNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity())
                    .setSmallIcon(R.mipmap.logo)
                    .setLargeIcon(BitmapFactory.decodeResource(getActivity().getResources(),
                            R.mipmap.logo))
                    .setContentTitle("Delivery Boy")
                    .setWhen(System.currentTimeMillis())
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setContentText("You have  Pending Orders");


    Intent notificationIntent = new Intent(getContext(), MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    // Add as notification
    NotificationManager manager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(0, builder.build());
}
Abhishek Kumar
  • 1,075
  • 10
  • 19

1 Answers1

1

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 https://design.google.com/icons/

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) {
    builder.setSmallIcon(R.drawable.icon_transperent);
} else { 
    builder.setSmallIcon(R.drawable.icon);
} 

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

Solution: For colored icons, use

defaultConfig {
        applicationId "com.your.app.pkj"
        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!!

Icon not displaying in notification: white square shown instead

omor
  • 907
  • 7
  • 18