首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android Notification.Builder:显示没有图标的通知

Android Notification.Builder:显示没有图标的通知
EN

Stack Overflow用户
提问于 2013-04-23 21:29:05
回答 6查看 15.2K关注 0票数 13
代码语言:javascript
复制
 String ns = Context.NOTIFICATION_SERVICE;
 NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

 int icon = R.drawable.ic_notification_icon;
 android.app.Notification.Builder nbuilder = new Notification.Builder(this);

 nbuilder.setContentTitle(getString(R.string.notifcation_title,mProfile.mName));
 nbuilder.setContentText(msg);
 nbuilder.setOnlyAlertOnce(true);
 nbuilder.setOngoing(true);
 nbuilder.setSmallIcon(icon,level.level);

如何隐藏或完全删除smallIcon?我试着不使用nbuilder.setSmallIcon,但结果是根本没有显示通知!

EN

回答 6

Stack Overflow用户

发布于 2013-04-24 21:20:49

在Jelly Bean和更高版本中,您可以使用nbuilder.setPriority(Notification.PRIORITY_MIN);对此优先级的确切解释由系统UI决定,但在AOSP中,这会导致通知的图标隐藏。

这是为不需要引起用户注意的“环境”或“背景”信息而设计的,但如果用户碰巧在通知面板周围闲逛,她可能会感兴趣。有关如何最好地使用通知优先级的详细信息,请参阅Notifications section of the Android Design site

票数 17
EN

Stack Overflow用户

发布于 2015-11-27 00:29:32

更新:不要在Android7上使用它,它会导致崩溃

使用反射,这是在棒棒糖(模拟器和Moto G设备)和棉花糖(模拟器)中工作的东西。

代码语言:javascript
复制
Notification notification = NotificationCompat.Builder.blabla().build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
  int smallIconViewId = context.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());

  if (smallIconViewId != 0) {
    if (notification.contentIntent != null)
      notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

    if (notification.headsUpContentView != null)
      notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);

    if (notification.bigContentView != null)
      notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE);
  }
}

我找不到更好的方法了。

这可能会在它们更改视图的id或更改通知中的任何RemoteViews字段时停止工作,因此使用风险自负。

票数 9
EN

Stack Overflow用户

发布于 2013-04-23 21:35:44

你不能这么做。如果没有setSmallIcon(icon,level.level);,则不会显示通知..

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16170648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档