How do I close a notification that doesn’t close?

Asked

Viewed 26 times

0

The following notification code I use but it does not close

    Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID_2)
            .setSmallIcon(playPauseBtn)
            .setLargeIcon(thumb)
            .setContentTitle(musicFiles.get(position).getTitle())
            .setContentText(musicFiles.get(position).getArtist())
            .setContentText(getString(R.string.app_name))
            .addAction(R.drawable.ic_skip_previous, "Previous", prevPending)
            .addAction(playPauseBtn, "Pause", pausePending)
            .addAction(R.drawable.ic_skip_next, "Next", nextPending)
            .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(0,1,2)
                    .setMediaSession(mediaSessionCompat.getSessionToken()))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setOnlyAlertOnce(true)
            .setContentIntent(contentIntent1)
            .setShowWhen(false)
            //.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setAutoCancel(true)
            .build();
    startForeground(2, notification);
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.