I'm trying to dismiss a notification from the foreground service but yet find any solutions. I'm not using notificationManager.notify(...) but startForeground(...) instead.
My NotificationCompat.Builder
Intent actionCancelNotification = new Intent(MusicPlayerApp.getAppContext(), NotificationReceiver.class);
actionCancelNotification.setAction(ACTION_DISMISS_NOTIFICATION);
actionCancelNotification.putExtra(PLAYBACK_NOTIFICATION_ID, PLAYBACK_NOTI_ID);
PendingIntent dismissNotiPendingIntent = PendingIntent.getBroadcast(MusicPlayerApp.getAppContext(), 0, actionCancelNotification, 0);
    //NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
       .setContentTitle("SongPlayback Notification")
       .setSmallIcon(R.drawable.ic_playback_notification_icon)
       .setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
       .setContentText("this is content text")
       .setSubText("sub text")
       .setDeleteIntent(dismissNotiPendingIntent)
       .build();
Even if i setOnGoing(false); it still did not work. I have followed this thread solution: Make a notification from a foreground service cancelable once the service is not in foreground anymore
and this is the new NotificationCompat.Builder as the official document written:
//NotificationCompat.Builder
builder.setCustomBigContentView(getRemoteView())
       .setContentTitle("SongPlayback Notification")
       .setSmallIcon(R.drawable.ic_playback_notification_icon)
       .setLargeIcon(BitmapFactory.decodeResource(MusicPlayerApp.getAppContext().getResources(), R.drawable.ic_playback_notification_icon))
       .setContentText("this is content text")
       .setSubText("sub text")
       //this did not work too
       .setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(MusicPlayerApp.getAppContext(), PlaybackStateCompat.ACTION_STOP)) //this d
       .build();
I wonder if any solutions to solve my problem. Thank you
You can make the notification dismissible by swiping by;
stopForeground(false);
And to dismiss the notification totally;
stopForeground(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With