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;
}
Related
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've got a strange problem with notification icon today.
It looks like this :
(the white circle ...)
Did I do something bad ?
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon_notification)
.setContentTitle(this.getString(R.string.notification_title))
.setContentText(this.getString(R.string.notification_text))
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
Here is my icon image (freshly downloaded from here https://material.io/icons/#ic_photo) :
http://image.noelshack.com/fichiers/2016/44/1478185219-icon-notification.png
Did I miss something ?
For the record, I'm using SDK 24 and only created the hdpi resource folder for now.
Edit #1 : I've added the ldpi, mdpi and xhdpi icons, nothing change ...
Edit #2 : For more precision, I'm trying to create this notification from a service ... FCM messaging service ...
If your compileSDKversion is above 20 then notification icon should be a white-on-transparent background image. Otherwise the image will be rendered as a white colored image.
Please go through the below link too for guidelines to create the icon
https://www.google.com/design/spec/patterns/notifications.html
and also the notification icon generator.
https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.space.trim=1&source.space.pad=0&name=ic_stat_example
You must use a notification icon with no background. Android will add the circle background.
You can set background color with
.setColor(context.getResources().getColor(R.color.colorPrimary))
to match your app indentity.
Icon inside will remain white and circle will get the color you defined.
It seems to be a problem of cache during compilation ... The first image I was using was bad (fully colored), so I think my compilator created somekind of cache on the filename.
I work on Windows and did this : uninstall the app from my phone, invalidate all cache from Android sudio => at re-compilation, the icon was OK.
U need to have separate icon generated which will be white version of your launcher icon. U can use below link to generate such icon.
https://romannurik.github.io/AndroidAssetStudio/icons-notification.html#source.type=clipart&source.clipart=ac_unit&source.space.trim=1&source.space.pad=0&name=ic_stat_ac_unit
Note : You need to upload PNG image of your launcher icon with transparent background.
For setting icon u can have a method like this
private int getSmallIconForNotification(){
return (Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP)? R.mipmap.ic_stat_launcher : R.mipmap.ic_launcher;
}
Code usage:
private NotificationCompat.Builder createNotificationBuilder(){
return new NotificationCompat.Builder(this)
.setSmallIcon(getSmallIconForNotification())
.setContentTitle("New Message")
.setContentText("Hi there.....")
.setAutoCancel(true);
}
I had the same problem while the app is closed and this helped me
Unfortunately this was a limitation of Firebase Notifications in SDK 9.0.0-9.6.1. When the app is in the background the launcher icon is use from the manifest (with the requisite Android tinting) for messages sent from the console.
With SDK 9.8.0 however, you can override the default! In your AndroidManifest.xml you can set the following fields to customize the icon and color:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/notification_icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/google_blue" />
Note:- If device has android version above 20 you have to generate icon with transparent background and while generating notification use this snippet
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP){
currentapiVersion=R.mipmap.ic_notification_lolipop;
} else{
currentapiVersion=R.mipmap.ic_launcher;
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(currentapiVersion)......
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);
}
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.
I'd like to show a timestamp in an Android Notification, just like the Android Design Guidelines suggest. (see the first snapshot, "12:03PM" is what I want!).
I tried many different ways, I thought setWhen would do it, but it only seems to affect the ordering in the Notification tray. Any idea how to achieve that?
See my code below:
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_notify)
.setLargeIcon(largeIcon)
.setTicker(text)
.setNumber(unreadCount)
.setWhen((new Date()).getTime())
.setAutoCancel(true)
.setContentTitle(title)
.setContentText(text)
.setDefaults(Notification.DEFAULT_VIBRATE);
notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
I don't want to use a custom layout for the notification.
I think I found the answer myself, when seems to be displayed only on Android 4.0.3 and later.
My wife's Nexus S (4.0.3) shows it, and I just upgraded to 4.0.4 on my Galaxy Nexus and it magically started to work!
It also shows on older versions (2.3 for instance), but not on 4.0.2 !
Use setContentInfo and pass your date as a string into it.
From this link
public Notification.Builder setContentInfo (CharSequence info) Since: API Level 11
Set the large text at the right-hand side of the notification.
Large Text at the right hand side of the notification should be where you want to put time.
Also from the same link:
public Notification.Builder setWhen (long when) Since: API Level 11
Set the time that the event occurred. Notifications in the panel are
sorted by this time.
which means that setWhen only sorts the notifications, and doesn't set any text.