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.
- Notifications in Kotlin
- How to create project in Android Studio using Kotlin
- Android EditText in Kotlin
- Android LinearLayout in Kotlin
- Android RelativeLayout in Kotlin
- Android ListView in Kotlin
- Android FrameLayout in Kotlin
- Android TableLayout in Kotlin
- Android Toast in Kotlin
- Android Fade In/Out in Kotlin
- Android Slide Up/Down in Kotlin
- Android Animations in Kotlin
- Kotlin Android Tutorial
- Difference between Java and Kotlin in Android with Examples
- Why You Should Switch to Kotlin from Java to Develop Android Apps?
- How to send message on WhatsApp in Android using Kotlin
- Thread Priority in Kotlin & Android
- Running User Interface Thread in Android using Kotlin
- How to Add RangeSeekbar in Android Using Kotlin?
- Android WebView in Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.