This topic describes how to integrate the Real-time Conversational AI agent into your Android app.
Source code
Download link
You can download the source code from GitHub.
Directory structure
├── Android // The root directory of the Android project.
│ ├── AUIBaseKits // The basic components of AUI Kits.
│ ├── AUIAICall // The UI components.
│ ├── README.md
│ ├── app // The demo.
│ ├── build.gradle
│ └── settings.gradleEnvironment requirements
Android Studio plug-in V4.1.3
Gradle 7.0.2
Java Development Kit (JDK) 11 in Android Studio
Before you begin
Develop relevant API operations on your server or deploy the provided server source code. For more information, see Deploy a project.
Run the demo
After you download the source code, open the Android folder in Android Studio.
Open the build.gradle project file and modify the package ID.
Open the
AUIAICallAgentIdConfig.javafile to configure the agent ID and its region.// AUIAICallAgentIdConfig.java // Your voice agent ID. private static String VOICE_AGENT_ID = "<Your voice call agent ID from the console>"; // Your avatar agent ID. private static String Avatar_AGENT_ID = "<Your digital human call agent ID from the console>"; // Your vision agent ID. private static String VISION_AGENT_ID = "<Your visual understanding call agent ID from the console>"; // Configure the region. private static String Region = "cn-shanghai";NoteThe agent ID and region must match those in the console. To use a specific type of agent, set the corresponding agent ID.
Region name
Region ID
China (Hangzhou)
cn-hangzhou
China (Shanghai)
cn-shanghai
China (Beijing)
cn-beijing
China (Shenzhen)
cn-shenzhen
Singapore
ap-southeast-1
Use one of the following methods to start the AI agent:
App Server deployed: Open the
AppServiceConst.javafile and modify the domain name of the App Server.// AppServiceConst.java String HOST = "Domain name of your App Server";App Server not deployed: Open the
AUIAICallAuthTokenHelper.javafile and configure theEnableDevelopTokenparameter. Copy the ARTC AppID and AppKey from the console to generate the authentication token required for starting the AI agent on the application.ImportantThis method requires embedding your AppKey and other sensitive information into your application. It is for testing and development only. Never use this method in a production environment. Exposing your AppKey on the client side creates a serious security risk.
// AUIAICallAuthTokenHelper.java public class AUIAICallAuthTokenHelper { // Set to true to enable developer mode private static final boolean EnableDevelopToken = true; // Copy the AppID of the ARTC application from the console private static final String AICallRTCDevelopAppId = "The App ID for the ARTC service used by the agent"; // Copy the AppKey of the ARTC application from the console private static final String AICallRTCDevelopAppKey = "The App Key for the ARTC service used by the agent"; }To obtain the AppID and AppKey for the ARTC application:
Go to the AI Agents page in the IMS console. Click an agent to go to the agent details page.

Click ARTC application ID. You are redirected to the ApsaraVideo Live console, where the AppID and AppKey are provided.

Develop Conversational AI features
You can quickly integrate AUIAICall into your app by performing the following steps.
Integrate the source code
Download the source code from the repository. In the Android Studio menu, navigate to File > New > Import Module and import the AUIAICall and AUIBaseKits folders.
Modify the third-party library dependencies in the build.gradle file.
dependencies { implementation 'androidx.appcompat:appcompat:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.google.android.material:material:x.x.x' // Change x.x.x to the version compatible with your project androidTestImplementation 'androidx.test.espresso:espresso-core:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.aliyun.aio:AliVCSDK_ARTC:x.x.x' // Change x.x.x to the version compatible with your project implementation 'com.aliyun.auikits.android:ARTCAICallKit:x.x.x' implementation 'com.alivc.live.component:PluginAEC:2.0.0' }NoteLatest ARTC SDK version: 7.9.1
Latest AICallKit SDK version: 2.9.1.
Wait until the synchronization is complete.
Configure the source code
Make sure that all prerequisites are met.
Open the
AppServiceConst.javafile and modify the server domain name.// AppServiceConst.java String HOST = "Domain name of your App Server";NoteIf your App Server is not deployed, generate the authentication token on the app for quick testing and demonstrations.
Call API operations
After completing the preceding steps, you can call API operations in other modules of your app or on its homepage to start conversations with the AI agent. You can also modify the source code.
/** Make sure microphone and camera permissions are granted before starting. */
Context currentActivity = AUIAICallEntranceActivity.this;
Intent intent = new Intent(currentActivity, AUIAICallInCallActivity.class);
// Set the call type (audio, avatar, or vision). This must match the agent ID type.
ARTCAICallEngine.ARTCAICallAgentType aiCallAgentType =
ARTCAICallEngine.ARTCAICallAgentType.VoiceAgent;
// The agent ID. It cannot be nil.
String aiAgentId = "";
// The region where the agent is located. It cannot be nil.
String aiAgentRegion = "";
// The ID of the user joining the RTC call. We recommend using the user's logon ID.
String userId = "123";
// The authentication token. For more information, see https://www.alibabacloud.com/help/en/ims/user-guide/generate-artc-authentication-token
String token = "";
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_LOGIN_USER_ID, userId);
// The agent type
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_TYPE, aiCallAgentType);
// The agent ID
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_ID, aiAgentId);
// The region where the agent is located
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_REGION, aiAgentRegion);
// Set the authentication token
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_RTC_AUTH_TOKEN, token);
currentActivity.startActivity(intent);For more information about authentication tokens, see Generate an ARTC authentication token.