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 android.app.Notification instance and pass it to the android.app.NotificationManager 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):
Flags
The flags field of a Notification is a bit field with the following flags:
| Flag | Description |
|---|---|
| FLAG_AUTO_CANCEL | If the notification should be canceled when it is clicked by the user. |
| FLAG_FOREGROUND_SERVICE | If the notification represents a currently running service. |
| FLAG_INSISTENT | If the audio will be repeated until the notification is cancelled or the notification window is opened. |
| FLAG_NO_CLEAR | If the notification should not be canceled when the user clicks the Clear all button. |
| FLAG_ONGOING_EVENT | If the notification is in reference to something that is ongoing, like a phone call. |
| FLAG_ONLY_ALERT_ONCE | If the sound and/or vibration should play each time the notification is sent, even if it has not been canceled before that. |
| FLAG_SHOW_LIGHTS | If the LED should be turned on for this notification. |