我研究了我能找到的唯一答案:
如何使用以下方式取消通知:
NotificationManager notificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0);
这些都不是我要求的,因为通知被取消了。我已在通知中设置了两项操作:' Dismiss'和'开放活动'。顾名思义,点击两者后,上面的代码会执行并清除通知,但不会导致通知栏重新启动。这是必需的,特别是当第二个通知操作导致活动启动时。
我尝试使用Android Lollipop和Nougat,通知栏也没有重新启动。所以如果有人能够告诉我它是否可能以及如何。 感谢。
构建通知的代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder
.setSmallIcon(icon).setTicker(message).setWhen(when)
.setAutoCancel(true).setContentTitle("Kindly record your Voice")
.setColor(Color.RED);
notificationIntent = new Intent(this,ReminderReceiver.class);
notificationIntent.setAction("Record");
PendingIntent pendIntent1 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.common_google_signin_btn_icon_dark, "Record", pendIntent1);
notificationIntent2 = new Intent(this, ReminderReceiver.class);
notificationIntent2.setAction("Dismissed");
PendingIntent pendIntent2 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.starticon, "Dismiss", pendIntent2);
notificationIntent3 = new Intent(this, CancelReceiver.class);
PendingIntent pendIntent3 = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent3, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setDeleteIntent(pendIntent3);
notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(1, notification);
答案 0 :(得分:1)
可能看起来很奇怪,但是当有其他通知存在时,通知栏不会上升。如果您是唯一的通知,则单击时栏会自动向上滑动。