Android Notifications

A notification in Android is shown to the user by adding an icon to the status bar.

To create a notification, a Service must create a instance and pass it to the system service.

To begin with, a notification must be created and configured:

The notification system service may be obtained via Context#getSystemService(serviceId) method, and the notification then shown using NotificationManager#notify(id, notification):


The flags field of a Notification is a bit field with the following flags:

FLAG_AUTO_CANCELIf the notification should be canceled when it is clicked by the user.
FLAG_FOREGROUND_SERVICEIf the notification represents a currently running service.
FLAG_INSISTENTIf the audio will be repeated until the notification is cancelled or the notification window is opened.
FLAG_NO_CLEARIf the notification should not be canceled when the user clicks the Clear all button.
FLAG_ONGOING_EVENTIf the notification is in reference to something that is ongoing, like a phone call.
FLAG_ONLY_ALERT_ONCEIf the sound and/or vibration should play each time the notification is sent, even if it has not been canceled before that.
FLAG_SHOW_LIGHTSIf the LED should be turned on for this notification.