繁体   English   中英

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

[英]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());

建立通知后,您可以使其不可见:

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

为我工作。

试试吧

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM