我浏览了Stackoverflow并发现这个问题已经被问过了,但我没有找到任何解决方案。
我有一个带有两个按钮的自定义通知。我想在按下通知上的按钮后关闭状态栏面板,但不知道如何实现。如果我按通知本身(即contentIntent),则面板会关闭,这也是我对我的按钮所希望的。
这是我的通知代码:
Notification notification = new Notification(R.drawable.icon, "Service running", System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.contentIntent = openIntent;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
contentView.setOnClickPendingIntent(R.id.button1, stopIntent);
contentView.setOnClickPendingIntent(R.id.button2, addIntent);
notification.contentView = contentView;
notificationManager.notify(NOTIFICATION_ID, notification);