在通知栏中显示小图标但在通知面板中隐藏

Show Small Icon in notification Bar but hide in notification Panel

我试着在这个论坛上找到这个,我找到了几个,但没有一个适合我。我只需要将它隐藏在大图标旁边的通知面板中,但如果我隐藏它,它也会从通知栏中消失。

有没有办法像第一次和第四次通知那样只显示大图标?
这是我正在使用的代码:

mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent;

    Notification.Builder mBuilder =
            new Notification.Builder(this)
                    .setSmallIcon(R.mipmap.small_icon).setTicker(getApplicationContext().getResources().getString(R.string.app_name))
                    .setLargeIcon(largeIcon)
                    .setAutoCancel(true)
                    .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
                    .setLights(Color.GREEN, 1000, 1000)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setContentTitle(extras.getString("title"))
                    .setStyle(new Notification.BigTextStyle().bigText(extras.getString("message")))
                    .setContentText(extras.getString("message"));
        edit.putString(Config.FRAGMENT, extras.getString("fragment"));
        edit.commit();
        intent = new Intent(this, NavigationActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                intent, 0);
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

为我工作。

试一试

Notification.Builder builder=new Notification.Builder(this);
            builder.setContentIntent(intent)
                    .setSmallIcon(R.drawable.ic_notification).setTicker(context.getResources().getString(R.string.app_name))
                    .setContentTitle(context.getResources().getString(R.string.app_name))
                    .setContentText(message);
            Notification notification = builder.build();

您可以在构建通知后使其不可见:

int smallIconId = context.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName());
            if (smallIconId != 0) {
                notification.contentView.setViewVisibility(smallIconId, View.INVISIBLE);
                notification.bigContentView.setViewVisibility(smallIconId, View.INVISIBLE);
            }