Android NotificationCompat.Builder setsmallicon() not working - android

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.

Related

Why is my notification icon not displayed properly in Oreo?

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!!

Galaxy S7 Nougat Full Icons

I wanted to ask how to change the app icon of my app on a Galaxy S7 running on Android Nougat (see attached screenshot) to fill the whole icon space.
Is there a way to do this?
EDIT: I think it's because these apps have square icons and mine is circular. Is there a way to make it square for Galaxy S7 Nougat devices and for all others round?
You can disable this by adding a meta-data element to your manifest:
<application>
<meta-data android:name="com.samsung.android.icon_container.has_icon_container" android:value="true"/>
</application>
This solution is only for user's end:
Go to settings -> display -> icon frames -> icon only.
This should change the icons into full size icons.
From https://developer.android.com/about/versions/nougat/android-7.1.html
Apps can now define circular launcher icons, which are used on devices that support them. When a launcher requests an app icon, the framework returns either android:icon or android:roundIcon, depending on the device build configuration. Because of this, apps should make sure to define both android:icon and android:roundIcon resources when responding to launcher intents. You can use Image Asset Studio to design round icons.
While that may not be sufficient to deal with Samsung's "special" white frame for icons, this gif shows a few ideas for creating icons that look good whether they are the normal size or framed "Squircle" style.
https://www.androidcentral.com/sites/androidcentral.com/files/article_images/2016/12/squircles.gif
In any event this means you now have to worry about a normal icon, a round icon and a Samsung-ized icon and there is no way to provide an icon for the Samsung-specific launcher design.
I met the same problem and tried various things. Now I found one interesting thing.
If you make an icon without any transparency, the icon will be the full size on the Nougat android phone. When I made an icon in the paint.exe and saved it as .png, there was no problem.
I think this will help you.
EDIT : below is what I met, explained in my comment
EDIT2 : the sizes and shapes of two icons (with and without transparency) are identical. the only difference is one has transparency and the other has white background. Definitely I don't mean that I deleted transparency and enlarged the image.
EDIT3 : more explanation about my icons #Hadas

How can i convert an image to notification icon to use in android app?

I have tried built in tools in android studio using res -> new -> Image Asset and then selecting notification icon.But after selecting the images it shows some grey and black boxes and not image icon and doesn't show in notifications as well.
I have researched and found that image background should be transparent for it to work but that didn't work also. Also i have tried images of 24x24 size as recommended but couldn't get the icon working in my android app.
Thanks in advance for any useful suggestions.
For v21 and above--> In notification icon, only white and transparent colors are allowed. Use white color what u want to show, rest part make it transparent.
For v20 and below --> You can use any image with proper dimensions.
Refer here for details.

Notification icon is greyed out

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

Android Notification smallIcon not displaying properly

So I've been working with Android Notifications and after setting a large image, I found out that my small image is actually not displaying properly.
As you can see on the following screenshot of the lockscreen, the background of the small icon is transparent. I want to set a specific colour there, just like the one Outlook.com is using:
Another example where the small icon shows next to the large one (please take notice of the small icon which is actually displaying, but not really noticable because there is just no background):
I've been thinking about changing the small icon to include the background colour, but obviously the colour would also be shown in the statusbar and that's wrong.
Try setColor() with NotificationCompat.Builder to set the accent color, which should be used by the colored circle behind the icon.

Categories

Resources