Some apps have notifications which can´t be dismissed by swiping them away.
How can I manage such behaviour?
Some apps have notifications which can´t be dismissed by swiping them away.
How can I manage such behaviour?
In addition to Andro Selvas answer:
If you are using the NotificationCompat.Builder, just use
builder.setOngoing(true);
Use the flag,FLAG_ONGOING_EVENT
to make it persistent.
Notification notification = new Notification(icon, tickerText, when);
notification.flags = Notification.FLAG_ONGOING_EVENT;
Also you can check, FLAG_NO_CLEAR
This is not an answer, just additional information on the above answers.
build.setGoing(true)
and FLAG_ONGOING_EVENT
NO longer work on Android 14.
https://developer.android.com/about/versions/14/behavior-changes-all#non-dismissable-notifications
I used the below code to make my notification persistent:
startForeground(yourNotificationId,notificationObject);
To make it dismissable, just do the below:
stopForeground(true);
© 2022 - 2024 — McMap. All rights reserved.