Hello, How do i create the permanent notification like the first one for Battery Indicator?
4 Answers
In case you are using NotificationCompat.Builder
, you can use :
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
mBuilder.setOngoing(true); //this will make ongoing notification

- 5,364
- 4
- 43
- 59
-
3upvote because Now for creating notifications we should use Builder. – TechArcSri Sep 14 '15 at 08:07
-
1it need to targetSDK is 23 – zys Feb 27 '16 at 08:46
-
@Mahmoud how do I dismiss it later? – mehulmpt Jun 22 '17 at 13:50
-
1NotificationManager mNotifyMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotifyMgr.cancel(mNotificationID); – Ashraf Alshahawy Sep 22 '17 at 08:02
Assign Notification.FLAG_ONGOING_EVENT
flag to your Notification
.
Sample code:
yourNotification.flags = Notification.FLAG_ONGOING_EVENT;
// Notify...
If you aren't familiar with the Notification
API, read Creating Status Bar Notifications on Android developers website.

- 26,835
- 7
- 76
- 67
-
9Also you should start ongoing notifications with `Service.startForeground` NOT using `NotificationManager.notify()` – Blundell Mar 20 '12 at 08:55
-
5
-
3And how would I dismiss the notification once my ongoing task is over ? – Anurag-Sharma Nov 18 '15 at 09:33
It is actually recommended to bitwise-or notification flags, rather than set the flags directly. This allows you to set multiple flags at once.
For example:
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
will set both flags at once, whereas:
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
will only set the FLAG_SHOW_LIGHTS flag.

- 957
- 9
- 13
public static final int FLAG_ONGOING_EVENT
Since: API Level 1
Bit to be bitwise-ored into the flags field that should be set if this notification is in reference to something that is ongoing, like a phone call.
public static final int FLAG_FOREGROUND_SERVICE
Since: API Level 5 Bit to be bitwise-ored into the flags field that should be set if this notification represents a currently running service.

- 40,203
- 9
- 86
- 108