我浏览了 Stackoverflow 并看到有人问过这个问题,但我没有找到任何解决方案。
我有一个带有 2 个按钮的自定义通知。我希望在按下该通知上的按钮后关闭状态栏面板,但不知道如何操作。如果我按下通知本身(即 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);