Sushant
Sushant

Reputation: 1282

Lollipop notification icon too small

I'm trying this code,

NotificationCompat.Builder nfBuilder = new NotificationCompat.Builder(
            context)
            ..setContentTitle(
                    "XYZ")
            .setContentText("ABC")
            .setContentIntent(pIntent)
            .setDefaults(Notification.DEFAULT_ALL)
            .setOnlyAlertOnce(true)
            .setAutoCancel(true)
            .setPriority(Notification.PRIORITY_HIGH)
            .setSmallIcon(R.drawable.woj_ic_launcher);

    Notification notification = nfBuilder.build();

    NotificationManager nfManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    nfManager.notify(requestCode, notification);

Problem is, it works fine with all other platforms but with lollipop, it shows very small icon with grey circle around it. I tried changing icon sizes and using setLargeIcon() method but still no joy.

enter image description here

Upvotes: 9

Views: 4539

Answers (2)

Sushant
Sushant

Reputation: 1282

This is how it sorted out finally:

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext());
nBuilder.setContentTitle("notificationTitle");
nBuilder.setSmallIcon(R.mipmap.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher1);
nBuilder.setLargeIcon(bitmap);
nBuilder.setContentText(notificationText);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, nBuilder.build());
  1. Get a drawable/mipmap.
  2. Convert it to bitmap.
  3. Set the bitmap using setLargeIcon(Bitmap bitmap) method of NotificationCompat.Builder.

Note:setSmallIcon() is a mendatory method here. You can't skip it.

Upvotes: 1

Mariano Argañaraz
Mariano Argañaraz

Reputation: 1252

The image should have square proportion. Use this tool (https://romannurik.github.io/AndroidAssetStudio/icons-notification.html) and then make sure you use the "Api v11" icons, since they have the square proportion you need, the older version had a little more height.

Recap: I got to tell I don't really see you icon being too small, in fact that's the greatest icon size I could get, look..

The size is the same as yours

And for the "grey" background issue, is something like Notification.Builder.setColor(Color.RED) not working for you?

Upvotes: 4

Related Questions