Quick start
This doc will guide you to integrate the In-app Chat Kit and start a chat quickly.
Prerequisites
- Go to ZEGOCLOUD Admin Console and do the following:
- Create a project, and get the
AppID
andAppSign
of your project. - Activate the In-app Chat service.
- Create a project, and get the

- Environment-specific requirements:
- Android Studio Arctic Fox (2020.3.1) or later
- Android SDK Packages: Android SDK 30, Android SDK Platform - Tools 30
- An Android device or Simulator that is running on Android 5.0 or later and supports audio and video. We recommend you use a real device.
- Android device and your computer are connected to the internet.
Integrate the SDK
Add com.github.ZEGOCLOUD:zego_inapp_chat_uikit_android as dependencies
- Add the
jitpack
configuration
Enter your project's root directory, open the settings.gradle
file to add the jitpack to dependencyResolutionManagement
> repositories
like this:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// !mark(1:2)
maven { url 'https://maven.zego.im' } // <- Add this line.
maven { url 'https://www.jitpack.io' } // <- Add this line.
}
}
If you can't find the above fields in settings.gradle
, it's probably because your Android Gradle Plugin version is lower than v7.1.0.
For more details, see Android Gradle Plugin Release Note v7.1.0.
Enter your project's root directory, open the build.gradle
file to add the jitpack to allprojects
->repositories
like this:
allprojects {
repositories {
google()
mavenCentral()
// !mark(1:2)
maven { url 'https://maven.zego.im' } // <- Add this line.
maven { url "https://jitpack.io" } // <- Add this line.
}
}
- Modify your app-level
build.gradle
file
dependencies {
...
// !mark
implementation 'com.github.ZEGOCLOUD:zego_inapp_chat_uikit_android:+' // add this line in your module-level build.gradle file's dependencies, usually named [app].
}
Call the init method to initialize the In-app Chat Kit
import android.app.Application;
import com.zegocloud.zimkit.services.ZIMKit;
public class MyApplication extends Application {
public static MyApplication sInstance;
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
Long appId = ; // The AppID you get from ZEGOCLOUD Admin Console.
String appSign = ; // The App Sign you get from ZEGOCLOUD Admin Console.
// !mark
ZIMKit.initWith(this,appId,appSign);
// Online notification for the initialization (use the following code if this is needed).
ZIMKit.initNotifications();
}
}
Call the connectUser method on the login page to log in to the In-app Chat Kit.
You can customize rules to generate the user ID and user name. We recommend that you set a meaningful user ID. You can associate the user ID with your business account system.
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import im.zego.zim.enums.ZIMErrorCode;
import com.zegocloud.zimkit.services.ZIMKit;
public class MyZIMKitActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void buttonClick() {
// userId and userName: 1 to 32 characters, can only contain digits, letters, and the following special characters: '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '=', '-', '`', ';', '’', ',', '.', '<', '>', '/', '\'
String userId = ; // Your ID as a user.
String userName = ; // You name as a user.
String userAvatar = ; // The image you set as the user avatar must be network image. e.g., https://doc-media.zego.im/IMKit/avatar/avatar-0.png
connectUser(userId, userName,userAvatar);
}
public void connectUser(String userId, String userName,String userAvatar) {
// Logs in.
// !mark(1:8)
ZIMKit.connectUser(userId,userName,userAvatar, errorInfo -> {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Operation after successful login. You will be redirected to other modules only after successful login. In this sample code, you will be redirected to the conversation module.
toConversationActivity();
} else {
}
});
}
// Integrate the conversation list into your Activity as a Fragment
private void toConversationActivity() {
// Redirect to the conversation list (Activity) you created.
Intent intent = new Intent(this,ConversationActivity.class);
startActivity(intent);
}
}
Display the conversation component of the In-app Chat Kit
The layout of the ConversationActivity
is specified in activity_conversation.xml
:
public class ConversationActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// !mark
setContentView(R.layout.activity_conversation);
}
}
Ideally, by this point, your app will look like this:

Start a chat
The In-app Chat Kit supports the following features:
Whether starting a one-on-one chat or a group chat, the peer user you want to chat with/the users you want to invite to a chat group must have logged in to the In-app Chat UIKit at least once. Otherwise, an error will occur.
- Get the
userId
that is generated using your own business logic. (theuserId
here refers to the peer user you want to chat with.) - Fill in the
userId
parameter and run the following code:
private void startSingleChat(String userId) {
// !mark
ZIMKitRouter.toMessageActivity(this, userId, ZIMKitConversationType.ZIMKitConversationTypePeer);
}
- Get the
ids
andgroupName
that is generated using your own business logic. (theids
here refers to the ID list of the users that you want to invite to the group chat.) - Fill in the
ids
andgroupName
parameters and run the following code:
public void createGroupChat(List<String> ids, String groupName) {
if (ids == null || ids.isEmpty()) {
return;
}
// !mark(1:15)
ZIMKit.createGroup(groupName, ids, (groupInfo, inviteUserErrors, errorInfo) -> {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
if (!inviteUserErrors.isEmpty()) {
// Implement the logic for the prompt window based on your business logic when
// there is a non-existing user ID in the group.
} else {
// Directly enter the chat page when the group chat is created successfully.
ZIMKitRouter.toMessageActivity(this, groupInfo.getId(),
ZIMKitConversationType.ZIMKitConversationTypeGroup);
}
} else {
// Implement the logic for the prompt window based on the returned error info
// when failing to create a group chat.
}
});
}
- Get the
groupId
that is generated using your own business logic. (thegroupID
here refers to the group chat you want to join.) - Fill in the
groupId
parameter and run the following code:
public void joinGroupChat(String groupId) {
// !mark(1:9)
ZIMKit.joinGroup(groupId, (groupInfo, errorInfo) -> {
if (errorInfo.code == ZIMErrorCode.SUCCESS) {
// Enter the group chat page after joining the group chat successfully.
ZIMKitRouter.toMessageActivity(this, groupInfo.getId(), ZIMKitConversationType.ZIMKitConversationTypeGroup);
} else {
// Implement the logic for the prompt window based on the returned error info
// when failing to join the group chat.
}
});
}
Related guides
Click here to explore more UI components.
A quick guide to help you run the sample code.
Get support
Need help or want to raise your questions? Click the button below to join our Discord community to get quick responses.