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).
Related
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.
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 ?
In my application i need to show the notification using native android api.
I am showing the notification by settings small and large icons.In recent OS devices (from 4.4) application is showing both small and large icons .
is there anyway to hide small icon when user pull notification and only show the large icon.
I have searched for the answers,but did not find working solution.
Below is the code i am using .
`Notification.Builder builder = new Notification.Builder(getApplicationContext())
.setContentTitle("Title")
.setContentText("Content")
.setSmallIcon(R.drawable.notification_icon)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.pull_down_icon);
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
Notification mNotif = builder.build();
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, mNotif);`
below is my observations.
- when i set only small icon, then small icon is displayed for notification bar and when user pull the notification same icon is displayed.
- when i set both (small and large) notification shown the small icon but, when user pull it shows both small and large
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());
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).