title: call function when notfication is clicked Android
body: <p>instead of opening activity, I found that the broadcast receiver can do the trick but it's not working its is not sending an intent to my broadcast receiver. I don't know any workaround. eventually, I have to call the notification from a service. please give me a way to run a function on clicking the notification</p>
  <h2>Broadcast receiver class</h2>
  <pre><code>class broadcastReceiver : BroadcastReceiver() {
      override fun onReceive(context: Context?, intent: Intent?) {
          Log.d(Constants.TAG, &quot;onReceive&quot;)
  
      }
  }
  </code></pre>
  <h2>main activity code</h2>
  <pre><code>receiver = broadcastReceiver()
  
  registerReceiver(receiver, IntentFilter(&quot;com.example.andy.CUSTOM_INTENT&quot;))
  
          notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
  
          val intent = Intent(this, broadcastReceiver::class.java)
  
          val pendingIntent = PendingIntent.getActivity(this, 5, intent, PendingIntent.FLAG_UPDATE_CURRENT)
  
          // RemoteViews are used to use the content of
          // some different layout apart from the current activity layout
          val contentView = RemoteViews(packageName, R.layout.activity_after_notification)
  
          // checking if android version is greater than oreo(API 26) or not
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.O) {
              notificationChannel = NotificationChannel(channelId, description, NotificationManager.IMPORTANCE_HIGH)
              notificationChannel.enableLights(true)
              notificationChannel.lightColor = Color.GREEN
              notificationChannel.enableVibration(false)
              notificationManager.createNotificationChannel(notificationChannel)
  
              builder = Notification.Builder(this, channelId)
                  .setContent(contentView)
                  .setSmallIcon(R.drawable.ic_launcher_background)
                  .setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_launcher_background))
                  .setContentIntent(pendingIntent)
          } else {
  
              builder = Notification.Builder(this)
                  .setContent(contentView)
                  .setSmallIcon(R.drawable.ic_launcher_background)
                  .setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_launcher_background))
                  .setContentIntent(pendingIntent)
          }
          notificationManager.notify(1234, builder.build())
      }
  </code></pre>