Android Integration Guide
Integrate an AI real-time messaging agent into your Android app.
Source code
Download link
Download the source code from the GitHub repository.
Directory structure
├── Android // The root directory.
│ ├── 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 or later
Gradle: V7.0.2 or later
Java Development Kit (JDK) in Android Studio: JDK 11 or later
Prerequisites
The required interfaces are developed, or the server source code is deployed on your app server. For more information, see Deploy a project.
Run the demo
Open Android Studio and open the downloaded Android directory.
Modify the package ID in the build.gradle file.
In the
AUIAICallAgentIdConfig.javafile, setChatBot_AGENT_IDto the AI agent ID generated by the console, andRegionto where the AI agent was created.private static String ChatBot_AGENT_ID = "<AI agent ID>"; private static String Region = "<Region where the agent was created>";Region name
Region ID
China (Hangzhou)
cn-hangzhou
China (Shanghai)
cn-shanghai
China (Beijing)
cn-beijing
China (Shenzhen)
cn-shenzhen
Singapore
ap-southeast-1
Start the agent using one of the following methods:
When the app server is deployed: If the Alibaba Cloud server source code is deployed on your app server, modify the server domain in
AppServiceConst.java:// AppServiceConst.java String HOST = "Your app server domain";When the app server is not deployed: To run the demo without a deployed server, open
AUIAIChatAuthTokenHelper.java, setEnableDevelopTokento true, and copy the IM application's AppId, AppKey, and AppSign from the console to generate a client-side token.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.
// AUIAIChatAuthTokenHelper.java public class AUIAIChatAuthTokenHelper { // Set the value to true to enable Develop mode. private static final boolean EnableDevelopToken = true; // AppId of IM application copied from the console. private static final String AIChatIMDevelopAppId = "AppId of IM application"; // AppKey of IM application copied from the console. private static final String AIChatIMDevelopAppKey = "AppKey of IM application"; // AppSign of IM application copied from the console. private static final String AIChatIMDevelopAppSign = "AppSign of IM application"; }
Run the app to message the AI agent.
Develop Conversational AI capabilities
To integrate AUIAICall into your app:
Integrate the source code
Import AUIAICall
In Android Studio, choose File > New > Import Module and select the downloaded folder.
Modify the dependencies in the build.gradle file:
dependencies { implementation 'androidx.appcompat:appcompat:x.x.x' // Replace x.x.x with a version that is compatible with your project. implementation 'com.google.android.material:material:x.x.x' // Replace x.x.x with a version that is compatible with your project. androidTestImplementation 'androidx.test.espresso:espresso-core:x.x.x' // Replace x.x.x with a version that is compatible with your project. implementation 'com.aliyun.aio:AliVCSDK_ARTC:x.x.x' // Replace x.x.x with a version that is compatible with your project. implementation 'com.aliyun.auikits.android:ARTCAICallKit:x.x.x' implementation 'com.aliyun.sdk.android:AliVCInteractionMessage:x.x.x' }NoteThe minimum compatible version of the ARTC SDK is V7.1.0. Latest version: 7.10.0.
Latest version of AICallKit SDK: 2.11.0.
Latest version of AliVCInteractionMessage: 1.8.0.
Wait for the sync to complete.
Configure the source code
Modify the server domain in AppServiceConst.java.
// AppServiceConst.java
String HOST = "Domain name of your app server";If you have not deployed the app server, follow Step 4 in the "Run the demo" section to generate a client-side token for testing.
Call API operations
Call API operations in other modules of your app or on the homepage to start a conversation with the AI agent. Modify the source code as needed.
/** Make sure that you are authorized to use the microphone and camera. */
// The AI agent type.
ARTCAICallEngine.ARTCAICallAgentType aiCallAgentType =
ARTCAICallEngine.ARTCAICallAgentType.ChatBot;
// The AI agent ID, which cannot be empty.
String aiAgentId = "XXXXXX";
Context currentActivity = AUIAICallEntranceActivity.this;
Intent intent = new Intent(currentActivity, AUIAIChatInChatActivity.class);
// The ID of the user who joins the chat. We recommend using the user ID for login.
String userId = "123";
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_LOGIN_USER_ID, userId);
// The AI agent type.
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_TYPE, aiCallAgentType);
// The AI agent ID.
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_ID, aiAgentId);
currentActivity.startActivity(intent);