CometChatIncomingCall is a call-handling component. It renders when the logged-in user receives an incoming voice or video call, displaying the caller’s information and providing accept/reject controls. Wire it to CometChatOngoingCallActivity after the user accepts the call.
Kotlin
Java
CallHandlerActivity.kt
class CallHandlerActivity : AppCompatActivity() { private lateinit var incomingCall: CometChatIncomingCall override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_call_handler) incomingCall = findViewById(R.id.incoming_call) // Set the Call object received from CometChat SDK incomingCall.setCall(call) incomingCall.setOnAcceptClick { // Navigate to ongoing call screen } incomingCall.setOnRejectClick { // Dismiss the incoming call screen finish() } }}
CallHandlerActivity.java
public class CallHandlerActivity extends AppCompatActivity { private CometChatIncomingCall incomingCall; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_call_handler); incomingCall = findViewById(R.id.incoming_call); // Set the Call object received from CometChat SDK incomingCall.setCall(call); incomingCall.setOnAcceptClick(() -> { // Navigate to ongoing call screen }); incomingCall.setOnRejectClick(() -> { // Dismiss the incoming call screen finish(); }); }}
Prerequisites: CometChat SDK initialized with CometChatUIKit.init(), a user logged in, and the cometchat-chat-uikit-android dependency added.In your Activity, get a reference and set the Call object:
Kotlin
Java
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.layout_activity) val incomingCall = findViewById<CometChatIncomingCall>(R.id.incoming_call) incomingCall.setCall(call) // Required — pass the Call object from the SDK}
YourActivity.java
@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_activity); CometChatIncomingCall incomingCall = findViewById(R.id.incoming_call); incomingCall.setCall(call); // Required — pass the Call object from the SDK}
To add programmatically in an Activity:
Kotlin
Java
YourActivity.kt
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val incomingCall = CometChatIncomingCall(this) incomingCall.setCall(call) setContentView(incomingCall)}
What this does: Replaces the default accept-button behavior. When the user taps the accept button, your custom OnClick lambda executes instead of the built-in call-accept logic.
What this does: Replaces the default reject-button behavior. When the user taps the reject button, your custom OnClick lambda executes instead of the built-in call-decline logic.
What this does: Registers an error listener. If the component encounters an error, your callback receives the CometChatException so you can handle it with custom logic.
Verify: After setting an action callback, trigger the corresponding user interaction (tap accept, tap reject) and confirm your custom logic executes instead of the default behavior.
Small functional customizations such as toggling call sounds and setting custom ringtones.
Method
Description
Code
disableSoundForCalls
Disables the ringtone for incoming calls
.disableSoundForCalls(true);
setCustomSoundForCalls
Sets a custom ringtone from res/raw
.setCustomSoundForCalls(R.raw.custom_ringtone);
Verify: After calling disableSoundForCalls(true), confirm no ringtone plays on incoming calls. After calling setCustomSoundForCalls, confirm the custom sound plays.
Replace the entire incoming call card with a custom view.
Kotlin
Java
YourActivity.kt
cometchatIncomingCall.setItemView(view)
YourActivity.java
cometchatIncomingCall.setItemView(view);
What this does: Replaces the entire default incoming call card with your custom View. The custom view is responsible for rendering all caller information and call controls.
Replace the subtitle text below the caller’s name.
Kotlin
Java
YourActivity.kt
cometchatIncomingCall.setSubtitleView(view)
YourActivity.java
cometchatIncomingCall.setSubtitleView(view);
What this does: Replaces the default subtitle area of the incoming call screen with your custom View. Use this to show additional information below the caller’s name.
Verify: After setting any custom view slot, confirm the custom view renders in the correct position on the incoming call screen and displays the expected caller information.
cometchatIncomingCall.setOnAcceptClick { Log.d("IncomingCall", "Call accepted by user") // Proceed with default accept via ViewModel cometchatIncomingCall.viewModel.acceptCall(call)}
cometchatIncomingCall.setOnAcceptClick(() -> { Log.d("IncomingCall", "Call accepted by user"); // Proceed with default accept via ViewModel cometchatIncomingCall.getViewModel().acceptCall(call);});
Sets the Call object for the incoming call screen. Required for accept/reject actions to work correctly. The component extracts the caller’s name, avatar, and call type from this object.
These methods provide direct access to internal components for advanced use cases.
Method
Returns
Description
getViewModel()
IncomingCallViewModel
The ViewModel managing call state and actions
getBinding()
CometchatIncomingCallComponentBinding
The ViewBinding for the component’s root layout
Use these only when the standard API is insufficient. Directly manipulating the ViewModel or binding may conflict with the component’s internal state management.
In addition to XML theme styles, the component exposes programmatic setters for fine-grained control:
Method
Type
Description
setBackgroundColor
@ColorInt int
Background color of the component
setTitleTextColor
@ColorInt int
Text color for the caller name
setTitleTextAppearance
@StyleRes int
Text appearance for the caller name
setSubtitleTextColor
@ColorInt int
Text color for the call type subtitle
setSubtitleTextAppearance
@StyleRes int
Text appearance for the call type subtitle
setIconTint
@ColorInt int
Tint color for the call type icon
setVoiceCallIcon
Drawable
Custom icon for voice calls
setVideoCallIcon
Drawable
Custom icon for video calls
setAcceptCallButtonBackgroundColor
@ColorInt int
Background color for the accept button
setRejectCallButtonBackgroundColor
@ColorInt int
Background color for the reject button
setAcceptButtonTextColor
@ColorInt int
Text color for the accept button
setRejectButtonTextColor
@ColorInt int
Text color for the reject button
setAcceptButtonTextAppearance
@StyleRes int
Text appearance for the accept button
setRejectButtonTextAppearance
@StyleRes int
Text appearance for the reject button
setCornerRadius
@Dimension int
Corner radius of the component card
setStrokeWidth
@Dimension int
Stroke width of the component border
setStrokeColor
@ColorInt int
Stroke color of the component border
setAvatarStyle
@StyleRes int
Style for the caller avatar
Verify: The incoming call screen displays with a purple background (#AA9EE8), custom button colors, and avatars with rounded corners (8dp radius) and an orange background (#FBAA75).