java - 如何用新收到的通知替换旧通知,而不是在通知托盘中创建一堆通知?
问题描述
我在通知面板中遇到通知问题。如果在应用程序处于后台时收到新通知时通知中存在旧通知,我需要清除旧通知。我能做什么或如何用新通知替换旧通知。或者,如果应用程序在后台或被杀死,是否有可能根据收到的通知启动应用程序/活动?这是我的通知代码。
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());
推荐阅读
- tiddlywiki5 - tiddlywiki 中的简单数据结构
- php - Java中的类似程序显示不同的值
- installation - 有没有办法在 install4j 中查看浮动许可证服务器的详细信息
- django - Django + AWS Secret Manager 密码轮换
- python - 如何在张量流中使用相同的权重进行初始化?
- google-classroom - 使用 Google 课堂分享按钮添加作业
- python - 使用 PyTorch 加载模型、优化器和调度器后训练损失增加
- python - pyfpdf:FPDF 错误:未定义字体:calibri B
- google-apps-script - 谷歌脚本的简单时区问题
- grid - 是否可以创建地球的运动模型(例如地震的冲击波?)