Open In App

Android progress notifications in Kotlin

Last Updated : 29 Dec, 2019
Like Article
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. \\* \\*
  1. Small IconRequired, can be set with setSmallIcon().
  2. Application NameProvided by the system.
  3. Time StampProvided by the system but can be overridden.
  4. Large IconOptional, can be set with setLargeIcon().
  5. TitleOptional, can be set with setContentTitle().
  6. TextOptional, 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.


package com.gfg.progressnotificationdemo
import android.os.Build
class App : Application(){
    val channelId = "Progress Notification" as String
    override fun onCreate(){
    //Check if the Android version is greater than 8. (Android Oreo)
    private fun createNotificationChannels(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val channel1 = NotificationChannel(
                "Progress Notification",
    //IMPORTANCE_HIGH = shows a notification as peek notification.
    //IMPORTANCE_LOW = shows the notification in the status bar.
            channel1.description = "Progress Notification Channel"
            val manager = getSystemService(

\\* Now, in the main activity we'll use a thread to invoke the notification. \\*


package com.gfg.progressnotificationdemo
import android.content.Intent
import android.os.Bundle
import android.os.SystemClock
import android.view.View
import com.gfg.progressnotificationdemo.R.drawable
class MainActivity : AppCompatActivity(){
    private lateinit var notificationManager: NotificationManagerCompat
    val channelId = "Progress Notification" as String
    override fun onCreate(savedInstanceState: Bundle?){
    //Create a Notification Manager
        notificationManager = NotificationManagerCompat.from(this)
    //Start() is called when the buttons is pressed.
    public fun start(view: View){
        val intent = Intent(this,{
            flags = Intent.FLAG_ACTIVITY_NEW_TASK or 
        val pendingIntent: PendingIntent = PendingIntent.getActivity(
         this, 0, intent, 0)
    //Sets the maximum progress as 100
        val progressMax = 100
    //Creating a notification and setting its various attributes
        val notification =
            NotificationCompat.Builder(this, channelId)
                .setProgress(progressMax, 0, true)
    //Initial Alert
            var progress = 0
            while (progress <= progressMax) {
                progress += 20
    //Use this to make it a Fixed-duration progress indicator notification
    //.setProgress(progressMax, progress, false)
            notification.setContentText("Download complete")
                .setProgress(0, 0, false)


Activity Main.xml

Layout consists of a single button.
<?xml version="1.0" encoding="utf-8"?>
        android:text="Show Notification"
        app:layout_constraintTop_toTopOf="parent" />



  • 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.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads