我在通知面板中遇到通知问题。当应用程序在后台时收到新通知时,如果旧通知存在于通知中,我需要清除旧通知。我能做什么或者如何用新通知替换旧通知。或者,如果应用程序在后台或被杀死,是否有可能根据收到的通知启动应用程序/Activity ? 这是我的通知代码。
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title);
builder.setContentText(message);
builder.setAutoCancel(true);
builder.setLights(ContextCompat.getColor(this, R.color.colorPrimary), 50, 50);
builder.setSmallIcon(R.drawable.notification);
builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
builder.setVibrate(new long[]{500, 500});
Intent intent = new Intent(this, LauncherActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notification_id, builder.build());
最佳答案
只有notificationID,相同
notificationManager.notify(0, builder.build());
关于java - 如何用新收到的通知替换旧通知,而不是在通知托盘中创建一堆通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58970906/