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...
})
CallSession callSession = CallSession.getInstance();
callSession.addButtonClickListener(this, new ButtonClickListener() {
@Override
public void onLeaveSessionButtonClicked() {
Log.d(TAG, "Leave button clicked");
}
@Override
public void onToggleAudioButtonClicked() {
Log.d(TAG, "Audio toggle button clicked");
}
@Override
public void 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
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()
}
@Override
public void onLeaveSessionButtonClicked() {
Log.d(TAG, "Leave button clicked");
// Show confirmation dialog before leaving
showLeaveConfirmationDialog();
}
private void showLeaveConfirmationDialog() {
new AlertDialog.Builder(this)
.setTitle("Leave Call")
.setMessage("Are you sure you want to leave this call?")
.setPositiveButton("Leave", (dialog, which) -> {
callSession.leaveSession();
})
.setNegativeButton("Cancel", null)
.show();
}
Use Cases:
- Show confirmation dialog before leaving
- Log analytics event
- Perform cleanup before leaving
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")
}
@Override
public void 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
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")
}
@Override
public void 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
Triggered when the user taps the switch camera button.
override fun onSwitchCameraButtonClicked() {
Log.d(TAG, "Switch camera clicked")
// Track camera switch analytics
}
@Override
public void 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
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()
}
@Override
public void 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
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"))
}
@Override
public void onShareInviteButtonClicked() {
Log.d(TAG, "Share invite clicked");
// Show custom share dialog
showShareDialog();
}
private void showShareDialog() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.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
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()
}
@Override
public void onChangeLayoutButtonClicked() {
Log.d(TAG, "Change layout clicked");
// Show layout options dialog
showLayoutOptionsDialog();
}
private void showLayoutOptionsDialog() {
String[] layouts = {"Tile", "Spotlight"};
new AlertDialog.Builder(this)
.setTitle("Select Layout")
.setItems(layouts, (dialog, which) -> {
LayoutType layoutType = (which == 0) ? LayoutType.TILE : LayoutType.SPOTLIGHT;
callSession.setLayout(layoutType);
})
.show();
}
Use Cases:
- Show custom layout picker
- Log layout change analytics
- Implement custom layout switching
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")
}
@Override
public void 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
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)
}
@Override
public void onChatButtonClicked() {
Log.d(TAG, "Chat button clicked");
// Open custom chat UI
openChatScreen();
}
private void openChatScreen() {
// Navigate to chat screen or show chat overlay
Intent intent = new Intent(this, ChatActivity.class);
intent.putExtra("sessionId", sessionId);
startActivity(intent);
}
Use Cases:
- Open custom chat interface
- Show in-call messaging overlay
- Navigate to chat screen
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()
}
@Override
public void onRecordingToggleButtonClicked() {
Log.d(TAG, "Recording toggle clicked");
// Show recording consent dialog
showRecordingConsentDialog();
}
private void showRecordingConsentDialog() {
new AlertDialog.Builder(this)
.setTitle("Start Recording")
.setMessage("All participants will be notified that this call is being recorded.")
.setPositiveButton("Start", (dialog, which) -> {
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"
}
}
public class CallActivity extends AppCompatActivity {
private static final String TAG = "CallActivity";
private CallSession callSession;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
callSession = CallSession.getInstance();
setupButtonClickListener();
}
private void setupButtonClickListener() {
callSession.addButtonClickListener(this, new ButtonClickListener() {
@Override
public void onLeaveSessionButtonClicked() {
showLeaveConfirmationDialog();
}
@Override
public void onToggleAudioButtonClicked() {
Log.d(TAG, "Audio toggle clicked");
}
@Override
public void onToggleVideoButtonClicked() {
Log.d(TAG, "Video toggle clicked");
}
@Override
public void onSwitchCameraButtonClicked() {
Log.d(TAG, "Switch camera clicked");
}
@Override
public void onRaiseHandButtonClicked() {
Toast.makeText(
CallActivity.this,
"Hand raised",
Toast.LENGTH_SHORT
).show();
}
@Override
public void onShareInviteButtonClicked() {
shareCallLink();
}
@Override
public void onChangeLayoutButtonClicked() {
showLayoutOptionsDialog();
}
@Override
public void onParticipantListButtonClicked() {
Log.d(TAG, "Participant list opened");
}
@Override
public void onChatButtonClicked() {
openChatScreen();
}
@Override
public void onRecordingToggleButtonClicked() {
showRecordingConsentDialog();
}
});
}
private void showLeaveConfirmationDialog() {
new AlertDialog.Builder(this)
.setTitle("Leave Call")
.setMessage("Are you sure you want to leave?")
.setPositiveButton("Leave", (dialog, which) -> {
callSession.leaveSession();
})
.setNegativeButton("Cancel", null)
.show();
}
private void shareCallLink() {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Join my call!");
startActivity(Intent.createChooser(shareIntent, "Share"));
}
private void showLayoutOptionsDialog() {
String[] layouts = {"Tile", "Spotlight"};
new AlertDialog.Builder(this)
.setTitle("Select Layout")
.setItems(layouts, (dialog, which) -> {
LayoutType layoutType = (which == 0) ? LayoutType.TILE : LayoutType.SPOTLIGHT;
callSession.setLayout(layoutType);
})
.show();
}
private void openChatScreen() {
// Open chat UI
}
private void showRecordingConsentDialog() {
new AlertDialog.Builder(this)
.setTitle("Start Recording")
.setMessage("All participants will be notified.")
.setPositiveButton("Start", (dialog, which) -> {
callSession.startRecording();
})
.setNegativeButton("Cancel", null)
.show();
}
}
Callbacks Summary
| Callback | Description |
|---|
onLeaveSessionButtonClicked | Leave session button was tapped |
onToggleAudioButtonClicked | Audio mute/unmute button was tapped |
onToggleVideoButtonClicked | Video on/off button was tapped |
onSwitchCameraButtonClicked | Switch camera button was tapped |
onRaiseHandButtonClicked | Raise hand button was tapped |
onShareInviteButtonClicked | Share invite button was tapped |
onChangeLayoutButtonClicked | Change layout button was tapped |
onParticipantListButtonClicked | Participant list button was tapped |
onChatButtonClicked | Chat button was tapped |
onRecordingToggleButtonClicked | Recording toggle button was tapped |
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()
SessionSettings sessionSettings = new 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