The One-to-One Chat feature provides a streamlined direct messaging interface, making it ideal for support chats, dating apps, and private messaging platforms. This setup eliminates distractions by focusing solely on a dedicated chat window.
Update the MainActivity to navigate to the MessageActivity:
MainActivity.kt
Copy
Ask AI
import android.os.Bundleimport android.util.Logimport androidx.activity.ComponentActivityimport androidx.activity.enableEdgeToEdgeimport com.cometchat.chat.core.CometChatimport com.cometchat.chat.exceptions.CometChatExceptionimport com.cometchat.chat.models.Userimport com.cometchat.chatuikit.shared.cometchatuikit.CometChatUIKitimport com.cometchat.chatuikit.shared.cometchatuikit.UIKitSettingsclass MainActivity : ComponentActivity() { private val TAG = "MainActivity" private val appID = "APP_ID" // Replace with your App ID private val region = "REGION" // Replace with your App Region private val authKey = "AUTH_KEY" // Replace with your Auth Key or leave blank if you are authenticating using Auth Token private val uiKitSettings = UIKitSettings.UIKitSettingsBuilder() .setRegion(region) .setAppId(appID) .setAuthKey(authKey) .subscribePresenceForAllUsers() .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() CometChatUIKit.init(this, uiKitSettings, object : CometChat.CallbackListener<String?>() { override fun onSuccess(successString: String?) { Log.d(TAG, "Initialization completed successfully") loginUser() } override fun onError(e: CometChatException?) {} }) } private fun loginUser() { CometChatUIKit.login("cometchat-uid-1", object : CometChat.CallbackListener<User>() { override fun onSuccess(user: User) { // Launch One-to-One or Group Chat Screen val intent = Intent(this@MainActivity, MessageActivity::class.java) intent.putExtra("uid", "cometchat-uid-1") startActivity(intent) } override fun onError(e: CometChatException) { // Handle login failure (e.g. show error message or retry) Log.e("Login", "Login failed: ${e.message}") } }) }}