How to add custom textview to .addaction for notification in Kotlin

i have this notification function that will send notification to user on specific time

private fun sendNotification(nextPray: Pray) {
createNotificationChannel(CHANNEL_ID2)
log("Send Notification")
//small view
val collapsedView = RemoteViews(
    packageName,
    R.layout.notification_collapsed
)
//big view
val expandedView = RemoteViews(
    packageName,
    R.layout.notification_expanded
)
val snoozeIntent = Intent(this, StopAlarm::class.java)
val snoozePendingIntent = PendingIntent.getBroadcast(this, 0, snoozeIntent, 0)
val notificationIntent = Intent(this, FullAzan::class.java)
val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)
expandedView.setTextViewText(R.id.text_view_collapsed_2, "Muazzin - ${nextPray.moazin}");
val mBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, CHANNEL_ID2)

        .setSmallIcon(R.drawable.qalby_ic)
        .setContentTitle("Tap to get the full Azan")
        .setContentText("Muazzin - ${nextPray.moazin}")
        .setCustomContentView(collapsedView)
        .setCustomBigContentView(expandedView)
        .setContentIntent(pendingIntent)
        .setPriority(NotificationCompat.PRIORITY_DEFAULT)
        .addAction(
            R.drawable.ic_stop,
            getString(R.string.text_stop),
            snoozePendingIntent
        )
        .setChannelId(CHANNEL_ID2)
        .setAutoCancel(true)
stopSelf()
val notification = mBuilder.build()
notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(100, notification)
//startForeground(100, notification)
log("vibrating")
vibrate()
log("Azan Audio Started")
MediaPlayerManager.getInstance(applicationContext).azan(nextPray)
}

and this is the custom view that i’m using:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="114dp"
android:background="@drawable/notifiction_bg_big"
>


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_gravity="center"
    android:layout_marginLeft="@dimen/_20sdp"
    android:layout_height="wrap_content">
    <ImageView
        android:layout_width="@dimen/_50sdp"
        android:layout_height="@dimen/_50sdp"
        android:src="@drawable/logoinnotifications"/>


</LinearLayout>

<LinearLayout
    android:layout_gravity="center"
    android:gravity="center"
    android:id="@+id/firstlinear"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/text_view_collapsed_1"
        style="@style/TextAppearance.Compat.Notification.Title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="@font/poppins_semibold"
        android:textSize="@dimen/_15sdp"
        android:text="Tap to get the full Azan"
        android:textColor="@color/white" />
    <TextView
        android:id="@+id/text_view_collapsed_2"
        android:textSize="@dimen/_12sdp"
        android:fontFamily="@font/poppins"
        style="@style/TextAppearance.Compat.Notification.Info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:text="Muazzin - Ustaz Mizi Wahid" />

    <TextView
        android:layout_marginTop="@dimen/_10sdp"
        android:id="@+id/text_view_collapsed_3"
        android:textSize="@dimen/_12sdp"
        android:fontFamily="@font/poppins_bold"
        android:gravity="center"
        style="@style/TextAppearance.Compat.Notification.Info"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/white"
        android:text="Stop Audio" />



</LinearLayout>

i want to add this id “text_view_collapsed_3” to .addaction so when the user click on it the audio will stop from notification

because the current one .addaction disappear when i apply the custom view

what is the correct way to achieve this?

Answer

SOLUTION:

expandedView.setOnClickPendingIntent(R.id.text_view_collapsed_3, snoozePendingIntent);