Android progress notifications in Kotlin
In this tutorial you’ll learn how to create a basic Progress Notification (Indeterminate progress indicator and Fixed-duration progress indicator) for Android using Kotlin.
Before we begin, let us first understand the components of a Notification in Android.
- Small Icon – Required, can be set with setSmallIcon().
- Application Name – Provided by the system.
- Time Stamp – Provided by the system but can be overridden.
- Large Icon – Optional, can be set with setLargeIcon().
- Title – Optional, can be set with setContentTitle().
- Text – Optional, can be set with setContentText().
Note : Notification Channels
Since the introduction of Android version 8 (Android Oreo), it is now compulsory to categorize all the notifications into categories called ‘channels’, this is for the convenience of users and also developers.
The image below shows us a notification channel named ‘Progress Notification’.
Since we only need to create a channel once, we’ll use a helper class ‘App.kt’ to get the job done.
Now, in the main activity we'll use a thread to invoke the notification.
Layout consists of a single button.
- Fixed-duration progress indicator : (after adding code in comments at line 67 of MainActivity.kt)
- Indeterminate progress indicator :
- After Download :
That’s how easy and simple it is to add progress indicator to a notification in Android using Kotlin.
Please Login to comment...