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).
Related
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 created an image in a 96x96 size, gave padding of 4px on all sides following this information.
Then I used Android Asset Studio to generate icons for different screens. But when I used these in my Notification Builder it is showing a grey box. Where am I doing wrong?
This is my image. Unable to display it here as background is transparent and image is white in color. Please download to see it.
I have the same problem. all my colors are white over transparent png, i still get plain white square on it. I checked the drawable folder have already generated 12 corresponding ic_stat_name.png file and they look as expected. But when i send notification the icon still appear white square.
I found the solution
Notification Icon with the new Firebase Cloud Messaging system
I use firebase notification which, according to the above source, will use the launcher icon instead of my expected ic_stat_name.png for notification
I have been having trouble with a icon showing with my notification. I have gone trough the material designs page for icons and Notification doc.
I used different scales, in BMP 256 color format: 360px, 144px, 48px, 24px 16px all continued showing a white block.
I changed format to PNG, used 144px (named "ic_notify_icon", used in code), still no luck.
//Global
private NotificationManager mNotifyManager ;
private Notification mNotify;
private void initialize() {
mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder mNotificationBuilder = new Notification.Builder(this);
mNotificationBuilder.setSmallIcon(R.mipmap.ic_notify_icon);
mNotificationBuilder.setContentTitle("A Title here");
mNotificationBuilder.setContentText("Some content text here");
mNotify = mNotificationBuilder.build();
ShowNotify();
}
private void ShowNotify(){
//...some code here
mNotifyMan.notify(0, mNotify);
//...some code here
}
Any suggestions?
p.s. I had a look at this post, also same question but I do not find it helpful/useful, or I just do not understand the requirements...
I have found the solution!
I only found hints on what the requirements are for a Android Notification (SDK 22 / Version 5.1.1)but after searching for over 4 hours, finally a complete and working solution for this.
Here are the steps I followed and it seems to be inline with what is mentioned on various forums, questions/answers and doc, but no "steps/requirements" of what is needed:
Creating and preparing your image
Create your image, however you want, take your app icon if you like:
Quick and dirty
Download an application to set transparency - I used IrfanView, it works well
Here is my image in IrfanView
Open your image in IrfanView, click File > Save As or press 's'
You should have a Save Dialog open (and a save options dialog, top right - if not, right at the bottom of the save dialog, select the Save options dialog checkbox, and it should open)
My settings (which were given by default) are:
Compression level - 6
Use main window color for transparency - Checked
Binary Encoding
(ICO): Use main window color for transparency - Checked
Check the following 2 boxes:
Save Transparent Color - Checked (I tried with only this checked, it didn't work - someone can extend on why not)
Save Transparentcy as Alpha Channel - Checked
Save as PNG file.
Save Box with Save Options
In Android Studio:
Right-Click Drawable folder > Add image asset (any resource folder should do)
Click on Notification Icon from the top drop-down list (default is Launcher Icon)
Select Image > Browse to image> click ok
You will notice your image is greyscale
this is normal since the Lollipop SDK (API 21 - Ver 5.0.1) only allows this type of color scheme, in searching I came across the materials design page which mentioned something in this line (Someone can extend on why this is)
Below, you will notice your notification icon in different 'dpi resolutions', adding a image normally will show a white block, but adding transparency solves this.
I believe one can use this from a 'colorful' perspective, in this case, IrfanView has a default background of black, this creating a "inverted" image in respect to this color (assuming in IrfanView, one leaves the "Use main windows color for transparency - checked" ) you can create different and interesting images.
I really hope this helps!
The notification icon in android must be transparent and have no background color!
If the icon have a rounded color background,
the icon will become a white rounded block.
Only an icon with a very transparent background can be used as a notification icon.
I have had this problem before, the problem is the size of the image you're using, try to resize it to 32x32 png.
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_tend_notification)
.setContentTitle(Constants.APP_NAME)
.setContentText(message)
.setTicker(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
convert your png icon from this link. hope it will help you.
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.
I am working on an app that sends notifications using the NotificationManager. I set up an Android Wear emulator and have my android phone connected to the emulator. The notifications my app generates appear on the Android Wear emulator, but the icons and color used are not what I'd expect.
The notification uses 1 of 3 icons as the notification icon, and sets a different LED color for each of the 3 cases. The notification I see on the watch emulator uses the app icon, and not the icon I set in the notification. Also, the background color of the notification is a solid red background, and I'm not sure what's setting it that color.
How can I get my notifications on the watch to match the icon of the notification I set, and how can I change the BG Color?!
Below, the Pink box is the application icon (and not the notification icon I'd expect).
Watch Notification
The notification icons come from the res/drawable folders of the handheld app. Do you have an icon with the same name in the res/drawable-hdpi folder?
http://developer.android.com/training/wearables/notifications/creating.html
Note: The bitmap that you use with setBackground() should have a resolution of 400x400 for non-scrolling backgrounds and 640x400 for backgrounds that support parallax scrolling. Place these bitmap images in the res/drawable-nodpi directory of your handheld app. Place other non-bitmap resources for wearable notifications, such as those used with the setContentIcon() method, in the res/drawable-hdpi directory of your handheld app.
As far I know the colors of the LED are irrelevant for wearable notifications. The background color is selected by default the icon and its priotity, if you set a big icon image it will use this. Since the quality of that big icon image meight be bad there is another call to achieve that. Here is a full example:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle("title")
.setContentText("message")
// replace the drawable if you want something else
.setSmallIcon(R.drawable.ic_launcher);
NotificationCompat.WearableExtender extender =
new NotificationCompat.WearableExtender();
Bitmap bg = BitmapFactory.decodeResource(context.getResources(),
R.drawable.background);
// in the line above you can change the background image
extender.setBackground(bg);
builder.extend(extender);
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(context);
notificationManager.notify(42, builder.build());