I'm trying to add an icon as indicated by number 5 in the image above. I'm using the InboxStyle class and the NotificationCompat.Builder to build it. I've already called setSmallIcon without luck. Any ideas?
Thanks!
As it turns out, this is simply a design change in the new version of Android.
Prior to Android 5.0 Lollipop, setLargeIcon sets the large icon on the left and setSmallIcon sets the small icon on the far right side, as you'd expect.
Starting in Android 5.0, setSmallIcon overlays a small icon on the bottom right corner of the large icon. As far as I can tell, there is no way to make the small icon appear on the far right in Lollipop. Please correct me if I'm wrong.
Related
In Redmi Note 5 Pro, I am using remoteviews for custom notifications. While doing this, the resource which i am passing using setsmallicon() is not being taken and plain solid square is being displayed. The resource is being used if it is not a custom notification.
Can someone help me solve this issue.
From android version lollpop onwards, they have made the changes for the notifications. When you are specifing the small icon, it should be of specific size as mentioned in this link.
The important thing is the image should be transparent and contains only white color.
Try using single color white with transparent background png file and add your icon in mipmap folder and your problem solved.
We have notifications in our app since a long time, which work fine. I have a small, multicoloured .png-icon we use for them, that have worked fine in the past.
In Oreo, the icon is not displayed properly, it is just a grey square. Looking at the drawer on the device, it seems that the system, gmail etc. all now have single-colour icons, so i suspect that it has something to do with that.
However, i can't find any documentation, design guidelines or anything that confirm this, so i am surrendering to a question here...
How can i make my icon display as normal in Oreo? What am i missing?
This is how i create the icon, from what i can see in documentation it should work, and it works pre-Oreo:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true).setContentTitle("Title").setWhen(when)
.setContentText(message).setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon("icon.png").setContentIntent(contentIntent);
getNotificationManager(context).notify(NOTIFICATION_ID, builder.build());
refer this site
In this site you may see this
You can see that I have set different small icons. Small icon need to
be vector icon on Lollipop and upper Android versions. Otherwise it
will show colored dot only as small icon.
If you have png,jpeg,jpg image file then convert it to svg and import this svg file into android studio using "Vector Asset" option and you are ready to go!!
In android notification, it's seam their is 3 different icons (see the picture below). I know how to set the large icon (via setlargeicon), however i don't know how to set the both 2 small icons as their is only one procedure setSmallIcon available.
It is the same setSmallIcon for both locations. However, you can also use setColor() to set the background color on the notification - that is how the lower icon gets the blue background.
I am working on android application . I need to create a notification for the app.
I am able to create it successfully using :
http://www.tutorialspoint.com/android/android_notifications.htm
I know NotificationCompat.Builder setNumber(int Number) . It sets the number on the notification on the right hand side . But instead of the number i want to show a small icon.
Do i need to use a custom layout , Because i am not able to find any API for this .
How do i do it .
To show an image at the bottom right end of the notification, we have to use the following APIs
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(baseContext).setLargeIcon(large_icon)
.setSmallIcon(small_icon);
For devices running up to android Kitkat the setLargeIcon sets the image at the left end, while the setSmallIcon sets the image at the bottom right end of the notification.
For devices running on higher than Kitkat
the setLargeIcon sets the image at the Left end, while the setSmallIcon sets the image at the bottom right end of the Large Image.
I used this simple code to set a Notification in Android 4.1 or higher.
It works well, but my problem comes with SmallIcon and LargeIcon.
I understand that SmallIcon is shown in the status bar and the LargeIcon is shown in the dropdown list.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("The ticker");
builder.setContentTitle("The title");
builder.setContentText("The text");
builder.setSmallIcon(R.drawable.my_small_icon);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.my_96px_large_icon);
builder.setLargeIcon(bm);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify("direct_tag", NOTIF_ALERTA_ID, builder.build());
My problem is:
When the notification is launched, a cropped oversized Small Icon is shown next to "The Ticker" text, instead of showing the original SmallIcon without oversizing it.
In the dropdown list I see the LargeIcon on the left, that's good. But I also see the small icon on the right, next to the time of the notification. I don't want to show that.
In my application I provide large (128x128 px) PNG drawable as small icon, and it shows scaled and without cropping. Is your drawable defined in bitmap file or maybe as XML resource? In XML you can specify several aspects of display (e.g. cropping). Double check your XML or use just PNG/JPG.
As Android API documentation on Notification.setSmallIcon() clearly states:
Set the small icon resource, which will be used to represent the notification in the status bar. The platform template for the expanded view will draw this icon in the left, unless a large icon has also been specified, in which case the small icon will be moved to the right-hand side.
AFAIK there's no way you can override the behaviour, unless you provide your own notification template (via Notification.setContent()
There is a way around this weird implementation. Instead of using setLargeIcon use this:
Notification notification=notificationBuilder.build()
notification.contentView.setImageViewResource(android.R.id.icon, R.drawable.your_large_icon);
I'd guess that this is the expected behavior.
You should check to see that your small icon follows the UX guidelines for icon size. Small icons are limited to 24x24dp.
The default behavior of an expanded notification is to show both the large icon and the small icon. I'm not sure that there's a way to get rid of the small icon, but why is this important?
In my case, I just set my red icon as the large icon and the setColor to Color.WHITE and set a white icon as my small icon. That way, in the notifications area, my red icon is shown and the white icon is "disapeared".
Bitmap icon = BitmapFactory.decodeResource(getResources(),R.drawable.app_logo);
mBuilder.setContentIntent(resultPendingIntent).setColor(Color.WHITE).setLargeIcon(icon);
In my case I had not placed icon image in all folders (xhdpi,hdpi,mdpi,ldpi).