Sometime back when I upgraded to lolipop on my Moto E the small notification icon turned black and white(I read that its the new google guidline). SO Ok I can live with it.
Now I have noticed that the icon has turned color again, and I havent changed my code and have been using the same drawable. It sure was showing black and white and now its colored.
My device is on Android 5.0.2
Also:
compileSdkVersion 22
buildToolsVersion "22.0.1"
targetSdkVersion 22
Here is my code:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setVibrate(new long[] { 10, 10, 10, 10, 10 })
.setSound(alarmSound)
.setSmallIcon(R.drawable.logo)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
Can anybody tell me how this happened?
It seems that ever since the android upgraded to lolipop the small icon on the notification comes in black and white only...
but it can be changed with the .setColor() method as shown in the code below.
Here's the code to set the color of the notification icon:-
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setSmallIcon(R.drawable.appypie_small);
notificationBuilder.setColor(getResources().getColor(R.color.notification_color));
}
else {
notificationBuilder.setSmallIcon(R.drawable.appypie_small);
}
Related
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.
I saw that google's gmail has a notification that shows with a small badge and i was wondering if that is something i can add to my notifications. Here is an example:
See the RED little badge hanging off the icon. is that something i can utilize. I am targeting the following in gradle:
minSdkVersion 19
targetSdkVersion 24
You can achieve this using
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(largeIcon)
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!
Surprising my APP's icon comes up with white color icon in notification bar on my Nexus 5. This is only in Nexus 5.
There is a question already about this the answer shows I need have: target 20. Which I have tried already: Like below no difference.
defaultConfig
{
applicationId "com.cn.redquest"
minSdkVersion 20
targetSdkVersion 20
versionCode 10
versionName "1.00"
}
Can somebody help me fix this?
Let me know!
Thanks!
Setting the target SDK to 20 means that you do not build your app for Android Lollipop. This will make your notification icon display all colors, but is not a long-term solution, since you will want to build for Lollipop (at least eventually).
At http://developer.android.com/design/style/iconography.html you can read about that the white style is how notifications are meant to be displayed in Lollipop (SDK 21). Google also suggests using a custom bg color - https://developer.android.com/about/versions/android-5.0-changes.html
I think a better solution is to actually provide the system with a silhouette icon, if the device is running Android Lollipop.
For instance:
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("My notification")
.setContentText("Look, white in Lollipop, else color!")
.setSmallIcon(getNotificationIcon())
.build();
And, in the getNotificationIcon method:
private int getNotificationIcon() {
boolean useSilhouette = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return useSilhouette ? R.drawable.ic_silhouette : R.drawable.ic_launcher;
}
I am adding two buttons to a notification in my app that is set to target API Level 8. The problem is that the two buttons appears as two large grey buttons, totally out of place with the rest of the notifications. I've tested it both on Nexus 7 and Galaxy Nexus.
All examples I've seen have the nice looking black buttons like the incoming call notification:
http://www.androidng.com/wp-content/uploads/2012/07/android-jelly-bean-notifications.jpeg
I would guess this would be easy, but no such luck today. Does anyone know where I might have taken the wrong turn? Below is a snippet of my code which generates the notification with the latest support library.
NotificationManager nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_stat_radio)
.setContentTitle(message)
.setTicker(message)
.setPriority(android.support.v4.app.NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setAutoCancel(false)
.addAction(android.R.drawable.ic_btn_speak_now, "Play", contentIntent)
.addAction(android.R.drawable.ic_dialog_map, "Stop", contentIntent)
.setContentText(message);
Notification n = builder.build();
//nm.notify(0, n);
startForeground(1, n);
So this is happening because your targetSdk in your AndroidManifest.xml is < 11.
I believe the change in compatibility that happens when you target 11 is that the default theme because Holo. Since yours (and my) target is less than 11, it's resorting to some compatibility theme that it applies on these buttons even though it shouldn't. I assume that even though your app / activity is set to Holo, it doesn't actually apply to the notification since they are are in a different process.
That's just my guess. Using CommonsWare's notification demo and just modify the targetSdk shows this behavior.
Im having the same issue, using Android studio (0.8.11) with Gradle (0.13.0)
compileSdkVersion 20
buildToolsVersion "20.0"
defaultConfig {
applicationId "x.xx.xxxxxx"
minSdkVersion 10
targetSdkVersion 20
versionCode x
versionName "x.xx"
}
Solve it by adding uses-sdk to the Manifest
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="20" />
I know the Manifest value will be overridden by Gradle value. but that solve it.