Reputation: 436
I want to make an Android Notification non-swipable so the user can only tap on it, but can't dismiss it.
So far I've found these two solutions:
Upvotes: 1
Views: 1110
Reputation: 4283
Both solutions make the notification non-dismissable, but calling .setOngoing(true)
makes the notification an ongoing notification, by setting its flag to Notification.FLAG_ONGOING_EVENT
.
With the flag Notification.FLAG_NO_CLEAR
, the notification stays a regular one.
Ongoing notifications differ from regular notifications in the following ways:
Ongoing notifications are sorted above the regular notifications in the notification panel
Ongoing notifications do not have an 'X' close button, and are not affected by the "Clear all" button.
Upvotes: 3
Reputation: 4487
They are very similar. FLAG_NO_CLEAR
is using when the notification should not be canceled when the user clicks the Clear all button. setOngoing
also change Notification.FLAG_ONGOING_EVENT
which has the same behavior but according to the doc
Ongoing notifications do not have an 'X' close button and when you engage your notification with a service, The service could control your notification dismissable.
Upvotes: 1