Skip to main content
Intercept UI button clicks with ButtonClickListener. This listener provides callbacks when users tap buttons in the call UI, allowing you to implement custom behavior or show confirmation dialogs.

Prerequisites

Register Listener

Register a ButtonClickListener to receive button click callbacks:
val callSession = CallSession.getInstance()

callSession.addButtonClickListener(this, object : ButtonClickListener() {
    override fun onLeaveSessionButtonClicked() {
        Log.d(TAG, "Leave button clicked")
    }

    override fun onToggleAudioButtonClicked() {
        Log.d(TAG, "Audio toggle button clicked")
    }

    override fun onToggleVideoButtonClicked() {
        Log.d(TAG, "Video toggle button clicked")
    }

    // Additional callbacks...
})
The listener is automatically removed when the LifecycleOwner (Activity/Fragment) is destroyed, preventing memory leaks.

Callbacks

onLeaveSessionButtonClicked

Triggered when the user taps the leave session button.
override fun onLeaveSessionButtonClicked() {
    Log.d(TAG, "Leave button clicked")
    // Show confirmation dialog before leaving
    showLeaveConfirmationDialog()
}

private fun showLeaveConfirmationDialog() {
    AlertDialog.Builder(this)
        .setTitle("Leave Call")
        .setMessage("Are you sure you want to leave this call?")
        .setPositiveButton("Leave") { _, _ ->
            callSession.leaveSession()
        }
        .setNegativeButton("Cancel", null)
        .show()
}
Use Cases:
  • Show confirmation dialog before leaving
  • Log analytics event
  • Perform cleanup before leaving

onToggleAudioButtonClicked

Triggered when the user taps the audio mute/unmute button.
override fun onToggleAudioButtonClicked() {
    Log.d(TAG, "Audio toggle clicked")
    // Track audio toggle analytics
    analytics.logEvent("audio_toggled")
}
Use Cases:
  • Log analytics events
  • Show tooltip on first use
  • Implement custom audio toggle logic

onToggleVideoButtonClicked

Triggered when the user taps the video on/off button.
override fun onToggleVideoButtonClicked() {
    Log.d(TAG, "Video toggle clicked")
    // Track video toggle analytics
    analytics.logEvent("video_toggled")
}
Use Cases:
  • Log analytics events
  • Check camera permissions
  • Implement custom video toggle logic

onSwitchCameraButtonClicked

Triggered when the user taps the switch camera button.
override fun onSwitchCameraButtonClicked() {
    Log.d(TAG, "Switch camera clicked")
    // Track camera switch analytics
}
Use Cases:
  • Log analytics events
  • Show camera switching animation
  • Track front/back camera usage

onRaiseHandButtonClicked

Triggered when the user taps the raise hand button.
override fun onRaiseHandButtonClicked() {
    Log.d(TAG, "Raise hand clicked")
    // Show hand raised confirmation
    Toast.makeText(this, "Hand raised", Toast.LENGTH_SHORT).show()
}
Use Cases:
  • Show confirmation feedback
  • Log analytics events
  • Implement custom hand raise behavior

onShareInviteButtonClicked

Triggered when the user taps the share invite button.
override fun onShareInviteButtonClicked() {
    Log.d(TAG, "Share invite clicked")
    // Show custom share dialog
    showShareDialog()
}

private fun showShareDialog() {
    val shareIntent = Intent(Intent.ACTION_SEND).apply {
        type = "text/plain"
        putExtra(Intent.EXTRA_TEXT, "Join my call: https://example.com/call/$sessionId")
    }
    startActivity(Intent.createChooser(shareIntent, "Share call link"))
}
Use Cases:
  • Show custom share sheet
  • Generate and share invite link
  • Copy link to clipboard

onChangeLayoutButtonClicked

Triggered when the user taps the change layout button.
override fun onChangeLayoutButtonClicked() {
    Log.d(TAG, "Change layout clicked")
    // Show layout options dialog
    showLayoutOptionsDialog()
}

private fun showLayoutOptionsDialog() {
    val layouts = arrayOf("Tile", "Spotlight")
    AlertDialog.Builder(this)
        .setTitle("Select Layout")
        .setItems(layouts) { _, which ->
            val layoutType = if (which == 0) LayoutType.TILE else LayoutType.SPOTLIGHT
            callSession.setLayout(layoutType)
        }
        .show()
}
Use Cases:
  • Show custom layout picker
  • Log layout change analytics
  • Implement custom layout switching

onParticipantListButtonClicked

Triggered when the user taps the participant list button.
override fun onParticipantListButtonClicked() {
    Log.d(TAG, "Participant list clicked")
    // Track participant list views
    analytics.logEvent("participant_list_opened")
}
Use Cases:
  • Log analytics events
  • Show custom participant list UI
  • Track feature usage

onChatButtonClicked

Triggered when the user taps the chat button.
override fun onChatButtonClicked() {
    Log.d(TAG, "Chat button clicked")
    // Open custom chat UI
    openChatScreen()
}

private fun openChatScreen() {
    // Navigate to chat screen or show chat overlay
    val intent = Intent(this, ChatActivity::class.java)
    intent.putExtra("sessionId", sessionId)
    startActivity(intent)
}
Use Cases:
  • Open custom chat interface
  • Show in-call messaging overlay
  • Navigate to chat screen

onRecordingToggleButtonClicked

Triggered when the user taps the recording button.
override fun onRecordingToggleButtonClicked() {
    Log.d(TAG, "Recording toggle clicked")
    // Show recording consent dialog
    showRecordingConsentDialog()
}

private fun showRecordingConsentDialog() {
    AlertDialog.Builder(this)
        .setTitle("Start Recording")
        .setMessage("All participants will be notified that this call is being recorded.")
        .setPositiveButton("Start") { _, _ ->
            callSession.startRecording()
        }
        .setNegativeButton("Cancel", null)
        .show()
}
Use Cases:
  • Show recording consent dialog
  • Check recording permissions
  • Log recording analytics

Complete Example

Here’s a complete example handling all button click events:
class CallActivity : AppCompatActivity() {
    private lateinit var callSession: CallSession

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_call)

        callSession = CallSession.getInstance()
        setupButtonClickListener()
    }

    private fun setupButtonClickListener() {
        callSession.addButtonClickListener(this, object : ButtonClickListener() {
            override fun onLeaveSessionButtonClicked() {
                showLeaveConfirmationDialog()
            }

            override fun onToggleAudioButtonClicked() {
                Log.d(TAG, "Audio toggle clicked")
            }

            override fun onToggleVideoButtonClicked() {
                Log.d(TAG, "Video toggle clicked")
            }

            override fun onSwitchCameraButtonClicked() {
                Log.d(TAG, "Switch camera clicked")
            }

            override fun onRaiseHandButtonClicked() {
                Toast.makeText(
                    this@CallActivity,
                    "Hand raised",
                    Toast.LENGTH_SHORT
                ).show()
            }

            override fun onShareInviteButtonClicked() {
                shareCallLink()
            }

            override fun onChangeLayoutButtonClicked() {
                showLayoutOptionsDialog()
            }

            override fun onParticipantListButtonClicked() {
                Log.d(TAG, "Participant list opened")
            }

            override fun onChatButtonClicked() {
                openChatScreen()
            }

            override fun onRecordingToggleButtonClicked() {
                showRecordingConsentDialog()
            }
        })
    }

    private fun showLeaveConfirmationDialog() {
        AlertDialog.Builder(this)
            .setTitle("Leave Call")
            .setMessage("Are you sure you want to leave?")
            .setPositiveButton("Leave") { _, _ ->
                callSession.leaveSession()
            }
            .setNegativeButton("Cancel", null)
            .show()
    }

    private fun shareCallLink() {
        val shareIntent = Intent(Intent.ACTION_SEND).apply {
            type = "text/plain"
            putExtra(Intent.EXTRA_TEXT, "Join my call!")
        }
        startActivity(Intent.createChooser(shareIntent, "Share"))
    }

    private fun showLayoutOptionsDialog() {
        val layouts = arrayOf("Tile", "Spotlight")
        AlertDialog.Builder(this)
            .setTitle("Select Layout")
            .setItems(layouts) { _, which ->
                val layoutType = if (which == 0) LayoutType.TILE else LayoutType.SPOTLIGHT
                callSession.setLayout(layoutType)
            }
            .show()
    }

    private fun openChatScreen() {
        // Open chat UI
    }

    private fun showRecordingConsentDialog() {
        AlertDialog.Builder(this)
            .setTitle("Start Recording")
            .setMessage("All participants will be notified.")
            .setPositiveButton("Start") { _, _ ->
                callSession.startRecording()
            }
            .setNegativeButton("Cancel", null)
            .show()
    }

    companion object {
        private const val TAG = "CallActivity"
    }
}

Callbacks Summary

CallbackDescription
onLeaveSessionButtonClickedLeave session button was tapped
onToggleAudioButtonClickedAudio mute/unmute button was tapped
onToggleVideoButtonClickedVideo on/off button was tapped
onSwitchCameraButtonClickedSwitch camera button was tapped
onRaiseHandButtonClickedRaise hand button was tapped
onShareInviteButtonClickedShare invite button was tapped
onChangeLayoutButtonClickedChange layout button was tapped
onParticipantListButtonClickedParticipant list button was tapped
onChatButtonClickedChat button was tapped
onRecordingToggleButtonClickedRecording toggle button was tapped

Hide Buttons

You can hide specific buttons using SessionSettings:
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
    .hideLeaveSessionButton(false)
    .hideToggleAudioButton(false)
    .hideToggleVideoButton(false)
    .hideSwitchCameraButton(false)
    .hideRaiseHandButton(false)
    .hideShareInviteButton(true)
    .hideChangeLayoutButton(false)
    .hideParticipantListButton(false)
    .hideChatButton(true)
    .hideRecordingButton(true)
    .build()

Next Steps