1

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?

1 Answers1

0

In Order to cancel or swipe foreground notification

ie .setOngoing(false) and .setAutoCancel(true)

You will have to kill the Service using `stopService()

NOTE:- The user is not allowed to swipe away a notification generated by an ongoing foreground service.

Quick learner
  • 10,632
  • 4
  • 45
  • 55