Lollipop notification icon too small - android

I'm trying this code,
NotificationCompat.Builder nfBuilder = new NotificationCompat.Builder(
context)
..setContentTitle(
"XYZ")
.setContentText("ABC")
.setContentIntent(pIntent)
.setDefaults(Notification.DEFAULT_ALL)
.setOnlyAlertOnce(true)
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH)
.setSmallIcon(R.drawable.woj_ic_launcher);
Notification notification = nfBuilder.build();
NotificationManager nfManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
nfManager.notify(requestCode, notification);
Problem is, it works fine with all other platforms but with lollipop, it shows very small icon with grey circle around it. I tried changing icon sizes and using setLargeIcon() method but still no joy.

The image should have square proportion.
Use this tool (https://romannurik.github.io/AndroidAssetStudio/icons-notification.html) and then make sure you use the "Api v11" icons, since they have the square proportion you need, the older version had a little more height.
Recap:
I got to tell I don't really see you icon being too small, in fact that's the greatest icon size I could get, look..
And for the "grey" background issue, is something like Notification.Builder.setColor(Color.RED) not working for you?

This is how it sorted out finally:
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext());
nBuilder.setContentTitle("notificationTitle");
nBuilder.setSmallIcon(R.mipmap.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher1);
nBuilder.setLargeIcon(bitmap);
nBuilder.setContentText(notificationText);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, nBuilder.build());
Get a drawable/mipmap.
Convert it to bitmap.
Set the bitmap using setLargeIcon(Bitmap bitmap) method of NotificationCompat.Builder.
Note:setSmallIcon() is a mendatory method here. You can't skip it.

Related

Notification icon not showing properly

I am trying to set a new notification icon for my app, however i cannot seem to make it work. I receive the notifications, but instead of my logo i see a black/grey circle in the status bar like this:
My MessageService looks like this:
public class MyMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this, MessageActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("notification_msg_id", remoteMessage.getData().get("my_msg_id"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder
= new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_stat_my_logo)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setColor(getResources().getColor(R.color.colorBlack))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
I generated the small icon with this (pretty great) tool and as you can see Android Studio is able to find the image in every size needed:
Here's my SDK versions:
I read earlier that there might be some problems with caching of drawables, i've tried invalidating every cache and cleaned/builded the project as well.
I've also tried different image files as well as xml vector drawables.
Do you guys have any idea what i'm doing wrong or how i can troubleshoot the issue further?
Thanks in advance!
Edit:
This is the icon i am trying to use in xxxhdpi-v11 format (it's white you probably need to click it to see it):
you got the same logo name in each folder maybe the one needed by the notifcation is different as notification icon must be of 24x24 dp
Notification icons must be entirely white for API 21 et later. try using this:
notification.setColor(getResources().getColor(R.color.notification_color));

Notification icon?

I create a notification via the standard code, the example below. Through the standard Image Asset I create an icon, I find it in the code.
When I start the notification, as an icon I see another icon, see the map.
Please tell me what I'm doing wrong?
Here's the process of creating an icon:
Create the Notification Icon
Go to File> New> Image Asset.
From the Icon Type dropdown, select Notification Icons.
Click on the icon next to the Clip Art item to select a material icon that you will use as the icon for your notification. In this example, you can use the Android icon.
public void onCreateNotif(View view) {
String chanal_Id = "default_chanal_id";
Intent resultIntent = new Intent(this, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, chanal_Id)
.setSmallIcon(R.drawable.ic_action1)
.setContentTitle("Title")
.setContentText("Notification text")
.setContentIntent(resultPendingIntent);
Notification notification = builder.build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, notification);
}
here is the file tree
here I see this icon in the notification
Updated Solution:
when you create Image Asset so It will create 3 Xmls files :
Background xml : it only contains on background color and shape
Foreground xml : it contains on foreground. only icon without
background color or shape
Integration of background and foreground xmls and it can be found in mipmap folder.
So To use the icon you have made in image asset change this line:
.setSmallIcon(R.drawable.ic_action1);
To:
.setSmallIcon(R.mipmap.ic_launcher);
or To this line if you wanted it rounded:
.setSmallIcon(R.mipmap.ic_launcher_round);

Why Notification does not show the correct smallIcon?

I use below code to display notifications in my Android apps. I can display it but both "small-Icon" and "large-Icon" are incorrect.They are not even launcher-icon.! I don't know Android where does they get from !!!!
My device is xiaomi-mi5s, is it related to my device? although other apps like Gmail show correct notifications.
I tested notifications in API 15,17,26 emulators and everything
NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(context, PRIMARY_CHANNEL)
.setSmallIcon(R.drawable.ic_stat_name)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setContentIntent(getPendingIntent(context))
.setContentTitle("This is dummy title")
.setContentText("This is dummy body text")
.setSound(getDefaultSoundUri())
.setCategory("My_Category")
.setDeleteIntent(getOnDismissedPendingIntent(context));
NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= 26) {
NotificationChannel chan1 = new NotificationChannel(PRIMARY_CHANNEL,
PRIMARY_CHANNEL, NotificationManager.IMPORTANCE_DEFAULT);
chan1.setLightColor(Color.BLUE);
chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
manager.createNotificationChannel(chan1);
}
manager.notify(12121, builder.build());
First of all, Large icon and Small icon can be different.
setSmallIcon(): sets an icon that should be displayed at status bar when notification was received. If setLargeIcon() was not called in the builder, large icon will use small icon drawable. Icon should have size of 24dp.
setLargeIcon(): sets an icon that should be displayed at notification in notification list, that can be opened by user by vertical dragging of status bar.
!!! Since API 21, Android requires you to use only single-colour icons with transparency for small icons (e.g. filled contour of Android with only white colour and transparent background).
As a Large icon, you can use icon of any colours, there are no restrictions.

how to display proper small icon for notification is not getting displayed in Lollipop and Android M

I am creating an application, I am able to display notification properly, but small icon is not getting displayed as I have mentioned it in the drawable folder, The icon is getting masked with white color. Can any one help me, how can I get the icon to display properly.
Below is my notification code:
nb = new NotificationCompat.Builder(context)
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSmallIcon(icon)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.micon_notification))
.setWhen(when)
.setContentIntent(contentIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setTicker(tickerText)
.setColor(Color.RED);
The icon mentioned in drawable is as shown below:
[1]: http://i.stack.imgur.com/ggYCY.png
That complete red color present inside the image is getting vanished and icon is getting displayed with complete white color. All suggestions are welcome.
This is the code Android uses to display notification icons:
if (entry.targetSdk >= Build.VERSION_CODES.LOLLIPOP) {
entry.icon.setColorFilter(mContext.getResources().getColor(android.R.color.white));
} else {
entry.icon.setColorFilter(null);
}
For that you've to make icon like Silhouette and make some section Transparent wherever you wants to add your Colors.
You can add your color using
.setColor(your_color_resource_here)
NOTE : setColor is only available in Lollipop so, you've to check OSVersion
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Notification notification = new Notification.Builder(context)
...
} else {
// Lollipop specific setColor method goes here.
Notification notification = new Notification.Builder(context)
...
notification.setColor(your_color)
...
}
Look at the documentation: http://developer.android.com/design/style/iconography.html
there are words:
"Notification icons must be entirely white. Also, the system may scale
down and/or darken the icons."
I hope it helps!

android wear notification with different text styles

On Add a Big View Google show how to make use of BigTextStyle. The screenshot looks very promising:
So I can see a title "Emmet Connolly" which I can set with setContentTitle().
And I can see a bold header "Re: wearables" which I don't know how to set.
Finally there is some text "Our devs are goint to be building a lot of really awesome apps" which should be set with setContentText().
I played around with some setters from NotificationCompat.BigTextStyle and I can summarize that some are ignored. Seems to be a bug ?!
final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender()
.setBackground(BitmapFactory.decodeResource(context.getResources(), R.drawable.chalk));
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("title")
.setContentText("text") // overwritten by bigText()
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("big text")
.setBigContentTitle("big content title") // ignored
.setSummaryText("summary text")) // ignored
.setContentIntent(viewPendingIntent)
.extend(wearableExtender);
final NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(notificationId, builder.build());
Html seems to work:
.setContentText(Html.fromHtml("<b>Best</b> restaurant <i>in</i> <font color=\"#0000ff\">San</font> Francisco <a href=\"http://www.stackoverflow.com\">#food"))
An here is a useful link: HTML Tags Supported By TextView

Categories

Resources