我正在尝试借助带有按钮的远程 View 来创建自定义通知。我想为此按钮编写 onclick 监听器,但问题是通知容器正在捕获触摸事件,并且按钮没有被单击。我的问题是有什么方法可以禁用此通知并让按钮被单击。我的代码如下所示:
Notification notification = new Notification(R.drawable.applogo,
"Apps activated", System.currentTimeMillis());
Intent notificationIntent = new Intent(getBaseContext(), AppsActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(),
0, notificationIntent , 0);
notification.contentIntent = pendingIntent;
//Remoteview and intent for my button
RemoteViews remoteView = new RemoteViews(getBaseContext().getPackageName(),
R.layout.customnotification);
Intent mIntent = getPackageManager().getLaunchIntentForPackage(c.getString(1));//starting some application through package
PendingIntent pintent = PendingIntent.getActivity(this, 0,
mIntent, 0);
remoteView.setOnClickPendingIntent(R.id.button1,
pintent);
notification.contentView = remoteView;
notificationManager.notify(CUSTOM_NOTIFICATION_ID, notification);
我正在开发 API 7。 谢谢
最佳答案
不幸的是,通知布局中的可点击按钮仅适用于 Custom notifications对于 API >= 11。
此外,对于 API >= 16,您可以使用 Notification Actions在通知中提供按钮。
关于android - 如何在自定义通知中的按钮上实现 onclick(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12798185/