Android 通知栏显示大图标和小图标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11024522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:46:32  来源:igfitidea点击:

Notification Bar shows both Large and Small Icons

androidnotificationsandroid-notificationsandroid-notification-bar

提问by D4N14L

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:

我的应用程序中的通知栏仅显示股票代码中的小图标(应该如此)。但是,当下拉“阴影”时,它会同时显示股票代码中的小图标,以及我在 Notification.Builder 中设置的大图标。这是我的代码:

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?

我不太明白为什么会这样。任何帮助?

回答by afollestad

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):

我认为这里的问题可能是您没有使用 Notificaiton.Builder 类。这是您可以做什么的一个小示例(尽管您必须插入自己的变量,并设置您使用的其他属性,例如振动):

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());

回答by ravyoli

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.

我在 android 棒棒糖中遇到的另一个问题是小图标显示在大图标旁边。要解决它 - 只是不要设置大图标!仅使用小图标设置。

回答by Adish Redd

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

http://developer.android.com/guide/topics/manifest/uses-sdk-element.html如果您将 android manifest 中的最大 sdk 版本设置为 19(即 KitKat),您的应用将不再显示针对棒棒糖的通知