In this article, we’ll learn notification basics in Android. We look at the frequently used terms and notification anatomy.
What are Notifications in Android?
A notification is a message that Android displays outside your app’s UI. Users can tap the notification to open your app or take an action directly from the notification.
There are terms used while implementing the notifications. Let’s look at them.
From Android 5.0, apps can display notifications in a floating window. They are called heads-up notifications.
They inform the user about the important information and only appear if the device is unlocked.
App Icon Badge:
From Android 8.0 (API level 26), launchers can indicate new notifications with a colored badge on the corresponding app icon. The badge is also known as a notification dot.
Users can touch & hold an app icon to see the notifications for that app. They can also act on notifications from that menu.
A notification contains different elements like a title, app icon, description, etc. Android system has a default template that puts all these elements together.
- Small icon: It is the required element. Generally, we display the app icon (logo).
- App name: It is provided by the system.
- Timestamp: It is the time that the event related to the notification occurred. Notifications in the panel are sorted by this time. It is provided by the system, but we can also override it.
- Large icon: It is optional, and usually used only for contact photos. Don’t add your app icon here.
- Title: Title of the notification (optional).
- Text: Message (or description) of the notification (optional).
Channels were introduced in Android 8.0 (API level 26). They help us to group the same types of notifications. They can then be turned on or off by the user.
You can find an app’s channels in the its settings. Go to Settings > All apps > open the app you want and tap on the Notifications. For example, the YouTube app developers created notification channels like this:
In the above image, “categories” refers to the “channels.”
Starting from Android 8.0 (API level 26), all notifications must be assigned to a channel or they will not appear.
The best thing about channels is that we can customize settings for each channel (like vibration, importance, and sound), and all the notifications posted to that channel will use those settings. Users can change them at any time by navigating to the settings of your app.
We can set the importance level for the notifications. The higher the importance, the more interruptive the notification is.
We have 4 importance levels:
- Urgent: makes a sound and appears as a heads-up notification.
- High: makes a sound.
- Medium: makes no sound.
- Low: makes no sound and doesn’t appear in the status bar.
Starting with Android 8.1, apps can only make a notification sound once per second. This means that if your app posts multiple notifications in one second, only the first one will make a sound. However, all of the notifications will still appear as expected.
Android also applies a rate limit when updating notifications. If you update a single notification too many times in less than one second, the system may drop some of the updates.
These are the basic terms used while implementing the notifications in Android. I hope you have learned something new. If you have any doubts, leave a comment below.
Most of the images in this post are taken from the official documentation.