将 onClicklistener 设置为通知

set onCliccklistener to notification

我有一个显示播放暂停的应用程序 notification.I 想在用户点击通知时调用应用程序中的服务,然后我在该服务中执行我的操作。

我已经为按钮等通知项小部件完成了此操作,但现在我想处理用户点击整个通知bar.any帮助?

这是我处理项目点击的代码:

Intent intent = new Intent(context , MyNotificationService.class);
intent.putExtra("ID","play");
PendingIntent pendingIntent = PendingIntent.getService(context,0,intent,0);
myRemoteView.setOnClickPendingIntent(R.id.myButton);
NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(this, YourActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(YourActivity.class);
stackBuilder.addNextIntent(resultIntent);

PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setContentIntent(resultPendingIntent);

好了 :) 当点击通知时,这将打开 'YourActivity'。