我试图在远程视图的帮助下创建一个自定义通知,上面有一个按钮。我想为此按钮编写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。 感谢
答案 0 :(得分:3)
不幸的是,通知布局中的可点击按钮仅适用于API {> = 11的Custom notifications。
此外,对于API> = 16,您可以使用Notification Actions在通知中提供按钮。