Android Notification - Small icon not working on some devices - android

According to https://developer.android.com/training/notify-user/build-notification#java I am creating a notification correctly.
I expect something as:
My code is:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, "channel")
.setSmallIcon(R.drawable.wesay_not)
.setContentTitle(notification.title)
.setContentText(notification.description)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setChannelId(context.getString(R.string.channel_id));
And the drawable is there:
However the device is showing the default android one, other applications seem to be showing the icon ok:

Probably that device you are using is xxxhdpi. and somehow it is taking default icon for those devices.
I suggest you remove your default icon from your project if you are not using it. And you can use Notification Icon Generator for generating icons for all size.

Ah, I just noticed that the XXHDPI icon is 128x128 and it should be 72x72, probably that has to do

find default icon named "wesay_not" in whole project first. If found than replace it with actual icon with folder related size.

Related

how to remove small notification icon in android studio apps

I'm building an android app which shows a notification when it's running. But the notification icon doesn't take the full size. Here is the code and an image of it.
NotificationCompat.Builder notificationBuilder=new
NotificationCompat.Builder(getActivity())
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.mipmap.ic_launcher);
enter image description here
when I set 'large icon', it takes the full size.
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
enter image description here
What I wanted to do is, remove the small icon and only keep the large icon which shows as a bigger icon. But if I removed 'setLargeIcon(int)' and keep 'setLargeIcon(bigmap)', app doesn't show any notificaitons. So in order to get notifications I have to keep both icons.
Could anyone give a solution for this. How can I keep only the large icon ?

Notification large icon always green robot

I try to show notification using NotificationCompat.Builder:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.ic_notification_small);
builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_notification_large));
builder.setContentTitle(context.getString(R.string.push_notification_received_title));
builder.setContentText("message");
((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
.notify(MESSAGE_NOTIFICATION_ID, builder.build());
But, instead large icon that I pointed on the builder in notification I get icon with a green robot (default icon like ic_luncher). I suppose problem may be that I use xiaomi device, but some applications like google translate show normal large icon.
After some of time I found a problem. Some of the shell (such as xiaomi) get large notification icon from launcher icon, so need to change launcher icon, reinstall application and reboot device for the changes to take effect (because icons placed in the cache).

android notification icon showing as white block

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.

Unexpected Icon and background color for Android Wear notification

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());

NotificationCompat 4.1 SetSmallIcon and SetLargeIcon

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).

Categories

Resources