title: Removing buttons from foreground service notification
body: <p>I have used foreground service but when the app is in bg, it shows task Completed which I dont want. How can I remove it? If this line (.addAction(R.drawable.ic_cancel, getString(R.string.remove_location_updates),
                          servicePendingIntent)) is removed, the bg service doesn't work. If this code is used: '.setContentIntent(servicePendingIntent)', when I click in the noti, the app doesn't open, noti closed and service stops. How can I solve it? Thanks in advance</p>
  
  <p><a href="https://i.stack.imgur.com/G0Jmk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G0Jmk.png" alt="enter image description here"></a></p>
  
  <pre><code>private Notification getNotification() {
      Intent intent = new Intent(this, LocationUpdatesService.class);
  
      CharSequence text = Utils.getLocationText(mLocation);
  
      // Extra to help us figure out if we arrived in onStartCommand via the notification or not.
      intent.putExtra(EXTRA_STARTED_FROM_NOTIFICATION, true);
  
      // The PendingIntent that leads to a call to onStartCommand() in this service.
      PendingIntent servicePendingIntent = PendingIntent.getService(this, 0, intent,
              PendingIntent.FLAG_UPDATE_CURRENT);
  
  
      PendingIntent activityPendingIntent = PendingIntent.getActivity(this, 0,
              new Intent(this, LiveTrack.class), 0);
  
      NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
              .addAction(R.drawable.ic_cancel, getString(R.string.remove_location_updates),
                      servicePendingIntent)
              .setContentIntent(activityPendingIntent)
  //                .setContentIntent(servicePendingIntent)
              .setContentText("App name")
              .setContentTitle(Utils.getLocationTitle(this))
              .setOngoing(true)
              .setPriority(Notification.PRIORITY_HIGH)
              .setSmallIcon(R.mipmap.ic_launcher)
              .setTicker(text)
              .setWhen(System.currentTimeMillis());
  
      // Set the Channel ID for Android O.
      if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
          builder.setChannelId(CHANNEL_ID); // Channel ID
      }
      return builder.build();
  }
  
  
  private void onNewLocation(Location location) {
  
      mLocation = location;
  
      // Notify anyone listening for broadcasts about the new location.
      Intent intent = new Intent(ACTION_BROADCAST);
      intent.putExtra(EXTRA_LOCATION, location);
      LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
  
      // Update notification content if running as a foreground service.
      if (serviceIsRunningInForeground(this)) {
          mNotificationManager.notify(NOTIFICATION_ID, getNotification());
      }
  }
  
  public boolean serviceIsRunningInForeground(Context context) {
      ActivityManager manager = (ActivityManager) context.getSystemService(
              Context.ACTIVITY_SERVICE);
      for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(
              Integer.MAX_VALUE)) {
          if (getClass().getName().equals(service.service.getClassName())) {
              if (service.foreground) {
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>