Notification ⭐

Notifications provide short, timely information about events in your app while it’s not in use.

Set Android Notification Properties

The properties of Android notification are set using NotificationCompat.Builder object. Some of the notification properties are mentioned below:

  • setSmallIcon(): it sets the icon of notification.
  • setContentTitle(): it is used to set the title of notification.
  • setContentText(): it is used to set the text message.
  • setAutoCancel(): it sets the cancelable property of notification.
  • setPriority(): it sets the priority of notification.

val notification= NotificationCompat.Builder(this, channel_id)
            .setContentTitle("Awesome Notification :)")
            .setContentText("This is the content text")

Create A Channel

  private fun createNotificationChannel(){
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            val channel= NotificationChannel(channel_id,channel_name,
            NotificationManager.IMPORTANCE_DEFAULT).apply {
                lightColor= Color.GREEN
            val manager = getSystemService(NOTIFICATION_SERVICE)as NotificationManager

// Create an explicit intent for an Activity in your app
      val intent= Intent(this,
      val pendingIntent= TaskStackBuilder.create(this).run{
          getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)


View Github