我试着在这个论坛找到这个,我发现了一对,但没有人为我工作。我只需要将它隐藏在大图标旁边的通知面板中,但是如果我隐藏它,它也会从通知栏中消失。
有没有办法只显示第一次和第四次通知中发生的大图标?
这是我正在使用的代码:
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());
答案 0 :(得分:7)
建立通知后,您可以将其隐藏起来:
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);
}
答案 1 :(得分:0)
为我工作。
试试吧
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();