Notifications显示所有以前的通知,而不仅仅是新的通知

问题描述 投票:0回答:1

[当我发出通知时,它会显示所有以前的通知,而不仅仅是新的通知。因此,第一个通知显示一个。我清除它,然后下一个通知显示两个。然后弹出所有三个下一个通知,依此类推。无论我尝试更改什么,要么我一次只能显示一个通知,要么一次只能显示所有通知。我只希望弹出新通知,而不会覆盖所有尚未清除的现有通知。

NotificationManagerCompat notifManager = NotificationManagerCompat.from(ctx);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
      NotificationChannel nc = new NotificationChannel(id, "Channel "+id, NotificationManager.IMPORTANCE_HIGH);
      notifManager.createNotificationChannel(nc);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx, id)
                .setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.ic_launcher_foreground))
                .setSmallIcon(R.drawable.ic_notif_1)
                .setPriority(NotificationCompat.PRIORITY_HIGH)
                .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
                .setColor(Color.rgb(160,0,200))
                .setContentTitle(title)
                .setContentText(text)
                .setAutoCancel(true)
                .setOnlyAlertOnce(true);

notifManager.notify(uuid, builder.build()); //each notif has a unique id
java android android-studio notifications notificationmanager
1个回答
0
投票

请按如下所示获取通知类中的当前时间英里

int  num = (int) System.currentTimeMillis();

并按如下所示在通知管理器中设置数字>>

   notificationManager.notify(num, notification);
© www.soinside.com 2019 - 2024. All rights reserved.