I am working an android project. I want to send notification when app is killed. I did it but, I can't remove notification when slide left or click notification. I try use
.setOngoing(false)
and
.setAutoCancel(true).
But, It doesn't work for me.
Intent notificationIntent = new Intent(Service.this, Message.class);
PendingIntent pendingIntent = PendingIntent.getActivity(Service.this,
0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(Service.this, CHANNEL_ID)
.setContentTitle("Message")
.setSmallIcon(R.drawable.message)
.setContentIntent(pendingIntent)
.setOngoing(false)
.setAutoCancel(true)
.build();
startForeground(1, notification);
I succes when use NotificationCompat.Builder, but startForeground don't accept that. What can I do?