![]() |
VOOZH | about |
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.
👁 ImageNote : Since the introduction of Android version 8 (Android Oreo), it is now compulsory to categorize all the notifications into categories called Notification Channels. This is for the convenience of users and also developers. The image below shows us a notification channel named 'Progress Notification'.
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language. Choose the API level according to your choice( Here we have chosen API Level 26).
Android 13 (API level 33) and higher need a permission for posting notifications from an app. For this, declare permission in the manifest file. Please manually make sure that the permission for notifications is provided for this app on phone.
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>Go to the activity_main.xml file and refer to the following code. We are just going to add a basic button to trigger the notification.
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.