Notifications in Android — Everything You Need to Know
Introducing with Notifications in Android — Part 1
Create a Basic Notification in Android — Part 2
Action Button & Broadcast Receiver — Part 3
I will write a series of articles about Notifications in Android, where I’m going to teach you everything you need to know about Notifications in Android. That series is also available in a video format as a playlist on my YouTube channel. This first article will be all about the introduction.
What is a Notification?
So a notification is basically a message that android displays outside of your applications UI to provide the user with some kind of reminders in most cases.
Notifications can appear to the users in a different locations and formats like for example as an icon in the status bar:
Then is a more detailed notification in the notification drawer:
As a badge on the application icon itself:
With the android API level 21 or Android 5.0 we can programmatically set the level of details that are visible in the notification on a secure lock screen
or whether the notification will show up on the lock screen at all.
We can also set the higher importance level for each notification so that we
can display so called heads-up notifications that are available only from an API level 21 which is Android 5.0.
And I’m going to talk about heads-up notifications in the separate article.
Notification Structure?
The actual layout design of a notification is determined by the Android System Templates and we can just use some of those templates to fill in the information. Of course there is always a way to customize the notification layout by yourself, and if you are planning to do that then you should consider a couple of different things which i am going to talk about in the separate article about it. But bottom line it’s always recommended to use a Standard Notification Templates when possible.
- Under the number of one we can see an icon and that icon is usually called
a Small Icon. - Then we have a text that does represent the Application Name itself.
- Then we have a Timestamp which is the value provided by the system. And of course we can programmatically override that value or even hide it using a setShowWhen() function.
- Then after that we have an image or an icon and this icon is called a Large Icon. So this element is optional and it’s mostly used to represent a person from your contact list for example and you shouldn’t use that large icon to
show your application icon or a logo because that would violate the user
experience. - Next we can see the Content Title which is also an optional element.
- Next we can see the Content Text which is an optional element.
- And finally there is a notification button that is called an Action Button
which is an optional element as well. It’s optimal to have a maximum of
three action buttons per notification, so be sure to remember that.
Notification Channels?
Starting with an API Level of 26 or Android 8.0, all notifications must be assigned to a channel or they will not appear.
In android developer terminology we use a word ‘channel’ while the actual users in their system settings see a word ‘category’ or a categories. By categorizing notifications into a channels a users can disable specific notification channel for your application instead of disabling all your notifications, and the users can control the visual and the auditory options for each channel all that from the android system settings.
For example you can create a notification channel for the news category of your application notifications, and then another channel for a reward notifications, and so on…
Notification Importance?
Android uses the importance of notification to determine how much the notification should interrupt the user. The higher the importance of a notification is, the more interrupted the notification will be.
On an API Level 26 and higher or Android 8.0 we are specifying notification
importance within the notification channel and the users can change this importance, in the system settings.
Also on the Android API Level 25 and below importance of each notification is determined by the notification priority, and there are four different importance levels: Urgent, High, Medium and Low.
With the Urgent, notification appear as a heads-up notification and they make a sound.
High importance basically means that notification will make a sound.
Medium importance means that notification will make no sound.
And the Low importance means that notification will have no sound and they will not exist or appear within the status bar.
Limitations?
Alright so that’s pretty much everything you need to know about the notifications in android for now. And the last thing that I want to share with you in this article, is about notification posting limits as well as some compatibility issues.
- Starting with the API Level of 27 or Android 8.1 applications cannot make a notification sound more than once per second.
So if your application posts multiple notifications in one second then they all appear as expected but only the first notification per second will make a sound.
- Android applies a Rate Limit when updating a notification so if you’re trying to post updates to a single notification too frequently.
For example many updates in less than a second then the android system might drop some of those updates.
And the last thing that i want to emphasize in this article, is the latest update for a notifications, for apps that are running on an API Level 26 and higher. With the newest updates some notification functionalities were moved away from a Notification Builder to a Notification Channel.
For example now you should use a Notification Channel’s setImportance() function, instead of a Notification Compat Builder’s setPriority() function when specifying the notification importance, to support newer API versions as well.