Android通知自定义视图:当应用程序终止时,无法单击自定义视图中的按钮

Android通知自定义视图:当应用程序终止时,无法单击自定义视图中的按钮,android,push-notification,notifications,custom-notification,Android,Push Notification,Notifications,Custom Notification,我为notification builder分配了一个自定义视图,并在自定义视图中设置了按钮单击的挂起意图,但当应用程序未运行时,按钮无法单击 我的实施: RemoteViews notificationLayout = new RemoteViews(getPackageName(),R.layout.emotions_notification); Intent veryDissatisfiedIntent = new Intent(this, ReceiverService.class)

我为notification builder分配了一个自定义视图,并在自定义视图中设置了按钮单击的挂起意图,但当应用程序未运行时,按钮无法单击

我的实施:

RemoteViews notificationLayout = new RemoteViews(getPackageName(),R.layout.emotions_notification);

Intent veryDissatisfiedIntent =  new Intent(this, ReceiverService.class);
intent.setAction(EMOTIONS_VERY_DISSATISFIED_ACTION);

PendingIntent pendingIntentVeryDissatisfied = PendingIntent.getService(this, id, veryDissatisfiedIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationLayout.setOnClickPendingIntent(R.id.sentiment_very_dissatisfied, pendingIntentVeryDissatisfied);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, channel_ID)

  .setPriority(NotificationCompat.PRIORITY_DEFAULT)
  .setSound(uri)
  .setAutoCancel(true);

  mBuilder.setContent(notificationLayout);
  mBuilder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
  mBuilder.setCustomBigContentView(notificationLayout);

 notificationManager.notify(id, mBuilder.build());
接收服务:

    public int onStartCommand(Intent intent, int flags, int startId) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        String action = intent.getAction();
        Bundle extras = intent.getExtras();
       int notificationId = extras.getInt("notificationId");
          switch (action) {
            case FirebasePluginMessagingService.EMOTIONS_VERY_DISSATISFIED_ACTION:
              // do something
              break;
}
   return START_STICKY;
  notificationManager.cancel(notificationId);
}
我通过以下方式解决了这个问题:

startForeground(id, mBuilder.build());