我研究和唯一的答案,我能找到要么说:如何以编程方式备份通知栏?
- 如何被拉低禁用通知栏。
如何使用取消通知:
NotificationManager notificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0);
这两个都不是我所要求的,因为通知被取消的很好。我在通知中设置了两项操作:“解除”和“打开活动”。顾名思义,点击两者后,上述代码将执行并清除通知,但不会导致通知栏恢复。这是必需的,特别是当第二次通知操作导致启动活动时。
我尝试了Android棒棒糖和牛轧糖,并且通知栏也没有恢复。所以如果有人能够告诉我这是否可能,以及如何。 谢谢。
建设的通知代码:
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);
您是否在通知构建器中尝试过.setAutoCancel(true)? –
是的,我有。没有帮助。 – Neurostic
您是否在活动中使用此代码? NotificationManager notificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); 为什么你要为所有通知设置相同的通知ID,你是否只想要一个通知? –