In my app, there is service running on background. I want to notify user that the service is running. But I need that user cannot delete the notification - by pressing clear button or by swipe it out, in notification bar
It means I need to show my notification above Notification area
First, press-and-hold on the persistent notification you want to remove. Another option is to swipe the notification left or right, and then tap on the cogwheel icon shown next to it. Next, tap on the switch next to Permanent to disable it, and then press Save.
The sticky notification ensures your device's complete protection by preventing Android from stopping Avast Mobile Security processes. On devices running Android 8.0 or higher, disabling the sticky notification is not an option.
This is possible but the way you implement it depends on the API level you develop for.
For API levels below 11, you can set Notification.FLAG_NO_CLEAR. This can be implemented like this:
// Create notification
Notification note = new Notification(R.drawable.your_icon, "Example notification", System.currentTimeMillis());
// Set notification message
note.setLatestEventInfo(context, "Some text", "Some more text", clickIntent);
// THIS LINE IS THE IMPORTANT ONE
// This notification will not be cleared by swiping or by pressing "Clear all"
note.flags |= Notification.FLAG_NO_CLEAR;
For API levels above 11, or when using the Android Support Library, one can implement it like this:
Notification noti = new Notification.Builder(mContext)
.setContentTitle("Notification title")
.setContentText("Notification content")
.setSmallIcon(R.drawable.yourIcon)
.setLargeIcon(R.drawable.yourBigIcon)
.setOngoing(true) // Again, THIS is the important line
.build();
To Create Non removable notification just use setOngoing (true);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_service_launcher)
.setContentTitle("My title")
.setOngoing(true)
.setContentText("Small text with details");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With