Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 614
Sushant Avatar asked May 10 '15 12:05

Sushant


2 Answers

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?

like image 168
Mariano Argañaraz Avatar answered Oct 05 '22 01:10

Mariano Argañaraz


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.

like image 20
Sushant Avatar answered Oct 05 '22 01:10

Sushant