Notification Bar shows both Large and Small Icons - android

The notification bar in my application shows only the small icon in the ticker (as it should). However, when the "shade" is pulled down, it shows both the small icon from the ticker, as well as a large icon that I set in the Notification.Builder. Here's my code:
if (Build.VERSION.SDK_INT > 10){
notification = new Notification(R.drawable.ic_stat_mintchip,
"This is a test",
System.currentTimeMillis());
notification.largeIcon = (((BitmapDrawable)c.getResources().getDrawable(R.drawable.ic_launcher)).getBitmap());
notification.defaults |= Notification.DEFAULT_ALL;
notification.number += 1;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
} else {
notification = new Notification(R.drawable.ic_stat_mintchip,
"This is a test",
System.currentTimeMillis());
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_ALL;
notification.number += 1;
}
}
I don't quite know why this is happening. Any assistance?

I think the issue here is possibly that you're not using the Notificaiton.Builder class. Here's a small example of what you could do (you would have to insert your own variables though, and set the other properties that you used such as vibration):
Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setLargeIcon(largeIcon)
.setSmallIcon(R.drawable.small_icon)
.setTicker(s.getText());
NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(100, nb.build());

Another issue i had in android lollipop is that the small icon was displayed next to the large icon. To solve it - just don't set the large icon! Use only the small icon setting.

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
if you set your max sdk version in android manifest to 19(i.e KitKat) Your app will no longer display notifications meant for lolipop

Related

Rich Push Notification not hiding the large icon on expanding the notification containing image

I am following the android developers docs to create an expandable notification containing one image.I have written the same code as per the docs but my large icon is not hiding after I expand my notification.
Here's my code:-
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, id)
.setSmallIcon(getNotificationIcon())
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
.setContentTitle(title)
.setContentText(data.get("message"))
.setLargeIcon(bitmap)
.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(bitmap)
.bigLargeIcon(null))
.setAutoCancel(true).setChannelId(id)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Notification notification = notificationBuilder.build();
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.flags |=
Notification.FLAG_AUTO_CANCEL; //Do not clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE;//Vibration
notificationManager.notify(mUniqueId, notification);
and android developer's code :-
Notification notification = new NotificationCompat.Builder(mContext, CHANNEL_ID)
.setSmallIcon(R.drawable.new_post)
.setContentTitle(imageTitle)
.setContentText(imageDescription)
.setLargeIcon(myBitmap)
.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(myBitmap)
.bigLargeIcon(null))
.build();
I am not able to understand whether I am missing something or doing it in wrong way. Please help . Thank You in advance.
I got the answer !!
Actually it is device specific issue.Some android devices are not hiding the large icon on expanding the notification and some devices are hiding it.

SmallIcon Color Turn To White Automatically Why In Notification Android?

public void animatedNotification() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(ic)
.setLights(Color.GREEN, 10000, 10000)
.setWhen(when)
.setPriority(Notification.PRIORITY_HIGH)
.setContentTitle(title)
.setContentText("Plants Need Watering Some of Your work is pending");
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
}
.setSmallIcon(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? R.mipmap.ic_launcher : R.drawable.notification_icon_bw_xhdpi)
.setColor(ResourcesCompat.getColor(getResources(), R.color.primary, getTheme()))
Use color to distinguish your app from others. Notification icons should only be a white-on-transparent background image. (https://developer.android.com/design/patterns/notifications.html)
Before Android Lollipop you can use same mipmap icon for all notification icon. But from Lollipop onwards you need to create new notification icon (Silhoette kind of icon).
Small icon appears white because of Material theme used for your app notification.

How to show notification in android with arabic text?

I developed android app which sends a notification in a particular time. The notifications works great and it shows arabic and english text well. but when i run the app on android device Nexus 5 with android version 5.1.1, the text notification in arabic appears as in a photo
Here's the code i used..
android.app.Notification notification = new android.app.Notification(R.drawable.ic_launcher,ticker, System.currentTimeMillis());
notification.setLatestEventInfo(activity, title, text, pendingIntent);
// Cancel the notification after its selected
notificationIntent.setAction(Long.toString(System.currentTimeMillis()));
// notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
notification.flags |= android.app.Notification.FLAG_AUTO_CANCEL;
notification.defaults |= android.app.Notification.DEFAULT_SOUND;
notification.defaults |= android.app.Notification.DEFAULT_VIBRATE;
NotificationManager notificationManager = (NotificationManager)activity.getSystemService(activity.NOTIFICATION_SERVICE);
notificationManager.notify(Id++, notification);
Try To use Arabic Reshaper
I used it to display arabic in law APIs before
https://github.com/agawish/Better-Arabic-Reshaper/blob/master/src/org/amr/arabic/ArabicReshaper.java

NotificationCompat.Builder setLights(); not working

I'm trying to use the LED on my notification and it's not working, i have this code:
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext());
nBuilder.setLights(Color.CYAN, 1000, 500);
The entire notification is working, like ContentTitle, ContentText and the notification is shown, but only the LED is not working.
Is there anything wrong with my code ? Should i use the Notification instead NotificationCompact.Builder ?
The LED light for notifications is turned on by the OS in the device only if the notification is triggered while the device screen is off.
Your code can not work, because you have to pass three variables:
the color
if turning on the led is on
if turning off the led is on
if you enable 2 and 3 your led will be blinking, if you disable 2 and 3 the led will be turned off
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context );
mBuilder.setLights(Color.RED, 1, 1); // will blink
That code seems OK, for the APIs before 26.
You might try adding Notification.FLAG_SHOW_LIGHTS
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(context);
nBuilder.setLights(Color.CYAN, 1000, 500);
Notification notif = nBuilder.build();
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(0, notif);
Also make sure that you do not swipe down to preview the notification, otherwise the LED will be off when the display goes black.

Android notificationlight not working

I'm using a notification to let the user now that the service is still running. Now I'd like to use the notificationlight to remind the user. (because it's fancy)
The notification works fine, but the notification light does nothing. Other applications work fine with the notification light, (gtalk, facebook)
it's more or less the example code for notifications with addition of these flags:
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.flags |= Notification.FLAG_NO_CLEAR + Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, notification);
and
notification.defaults |= Notification.DEFAULT_LIGHTS;
instead doesn't work either.
I'm debugging on a Galaxy Nexus with Android 4.0, but the app's target is Android 2.3.3
EDIT:
could this be a problem of permission? If yes, which one? I looked through all and found no matching permission for the notification light.
I think there is an error with the + operator, you need the OR:
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
EDIT: and if you are using flags, I think the right one should be:
notification.flags |= Notification.FLAG_SHOW_LIGHTS
On jelly bean devices, led only works if notification priority is set to max or default, please check again. Following snippet of code is working fine for me on jb devices.
notification.setLights(0xFF0000FF,100,3000);
notification.setPriority(Notification.PRIORITY_DEFAULT);
Here I'm showing blue color led for notification which will remain on for 100 ms and off for 3000 ms till user unlocks his device.
And check if you are using NotificationCompat (compatibility) class than ignore setDefaults method and use SetLight, SetSound, Setvibration, etc

Categories

Resources