Notification Bar shows both Large and Small Icons
Asked Answered
B

3

6

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?

Braziel answered 13/6, 2012 at 22:58 Comment(3)
Can you post a screenshot somewhere of what you are seeing?Edric
Sure, one second... imgur.com/07lxgBraziel
I assume that you are MintChip. I am not quite certain why you are getting that effect. What device is this? Note that while your question says you are using Notification.Builder, your code is not. You might consider using NotificationCompat.Builder from the Android Support project and see if that helps.Edric
N
11

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());
Naos answered 1/7, 2012 at 23:25 Comment(5)
I can't compile the 'nb.build()' in Android4.04, I use nb.getNotification() instead.Homeopathist
if i use a ticker text, which icon is used for it? and how can i customize it and use a different one for it and a different one for the notification itself?Antitrades
@androiddeveloper the small icon is shown in the status bar, the large icon is shown when you open the notification shade.Naos
@Naos is it possible to have a different icon for the ticker text and a different one for the notification?Antitrades
With above code if i set both small and large icons notification is displaying both small and large icon when user pull the notification. Running with below configuration. <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="24" /> any solution for this?Caryloncaryn
D
7

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.

Damara answered 12/2, 2015 at 15:48 Comment(2)
But I want to use both. any way to do that?Depolarize
If you set both icons, then both will appear.Damara
S
0

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

Selwin answered 15/3, 2016 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.