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
- Android TableLayout in Kotlin
- Android Animations in Kotlin
- Kotlin Android Tutorial
- Android EditText in Kotlin
- Android Fade In/Out in Kotlin
- Android Toast in Kotlin
- Android Slide Up/Down in Kotlin
- Android FrameLayout in Kotlin
- Android LinearLayout in Kotlin
- Android RelativeLayout in Kotlin
- Android ListView in Kotlin
- Thread Priority in Kotlin & Android
- How to create project in Android Studio using Kotlin
- Difference between Java and Kotlin in Android with Examples
- Why You Should Switch to Kotlin from Java to Develop Android Apps?
- Upload Progress Bar in PHP
- How to do box shadow with progress bar style using bootstrap?
- RadioButton in Kotlin
- Switch 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 firstname.lastname@example.org. 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.