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,但结果是根本没有显示通知!
发布于 2013-04-24 21:20:49
在Jelly Bean和更高版本中,您可以使用nbuilder.setPriority(Notification.PRIORITY_MIN);对此优先级的确切解释由系统UI决定,但在AOSP中,这会导致通知的图标隐藏。
这是为不需要引起用户注意的“环境”或“背景”信息而设计的,但如果用户碰巧在通知面板周围闲逛,她可能会感兴趣。有关如何最好地使用通知优先级的详细信息,请参阅Notifications section of the Android Design site。
发布于 2015-11-27 00:29:32
更新:不要在Android7上使用它,它会导致崩溃
使用反射,这是在棒棒糖(模拟器和Moto G设备)和棉花糖(模拟器)中工作的东西。
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字段时停止工作,因此使用风险自负。
发布于 2013-04-23 21:35:44
你不能这么做。如果没有setSmallIcon(icon,level.level);,则不会显示通知..
https://stackoverflow.com/questions/16170648
复制相似问题