AUI Kits for Chat Salon is a cross-platform real-time communication service from Alibaba Cloud. It supports use cases such as voice chat and real-time multi-user interaction. With its stable, smooth, and flexible communication features, AUI Kits helps you quickly launch applications using a low-code approach. This document describes how to integrate the Chat Salon feature on Android.
Source code
Source code download
Download the source code from the GitHub open-source project.
Directory structure
├── Android
│ ├── AUIBaseKits // AUI base components
│ ├── AUIVoiceRoom // UI components
│ ├── AUIVoiceRoomEngine // Scenario-based APIs
│ ├── README.md
│ ├── app // Demo entry point
│ ├── build.gradle
│ └── settings.gradle
Environment requirements
-
Android Studio plugin version 4.1.3
-
Gradle 7.0.2
-
JDK 11, included with Android Studio
Prerequisites
-
Complete the console configuration.
-
Develop the required server-side APIs or deploy the provided source code. For instructions, see Server-side configuration and operation.
Run the demo
This section describes how to compile and run the demo.
-
Download and unzip the demo package from MediaBox-AUIKits.
-
In Android Studio, open the demo project by choosing File > Open and selecting the downloaded project file.
-
Open the VoiceRoomServerConstant.java file and modify the server domain name and the appID of your Real-Time Communication application.
public class VoiceRoomServerConstant { public static final String APP_ID = "xxx"; public static final String HOST = "xxx"; } -
Physical device testing
-
Connect a physical Android device. Once connected, your device's name appears in the device selector in the Android Studio toolbar.
-
Click the green run button (▶) on the toolbar to build the project file.
-
Install and run the Interactive Live Streaming application on your physical Android device.
-
Quick development
Follow these steps to quickly integrate AUIVoiceRoom into your app and enable the Chat Salon feature.
Source code integration
-
Import the AUIVoiceRoom and AUIVoiceRoomEngine modules.
In Android Studio, choose File > New > Import Module and select the module folders from the downloaded repository.
-
Modify the third-party library dependencies in the build.gradle file.
dependencies { implementation 'androidx.appcompat:appcompat:x.x.x' // Replace x.x.x with the version compatible with your project implementation 'com.google.android.material:material:x.x.x' // Replace x.x.x with the version compatible with your project androidTestImplementation 'androidx.test.espresso:espresso-core:x.x.x' // Replace x.x.x with the version compatible with your project implementation 'com.aliyun.aio:AliVCSDK_Standard:x.x.x' // Replace x.x.x with the version compatible with your project } -
The source code integration is complete.
Source code configuration
-
Open the VoiceRoomServerConstant.java file and modify the server domain name.
// VoiceRoomServerConstant.java public static final String HOST = "Your application server domain name"; -
Open the VoiceRoomServerConstant.java file and modify the Real-Time Communication appID.
// VoiceRoomServerConstant.java
public static final String APP_ID = "Your Real-Time Communication appID";
Call APIs
Use the component APIs to implement the Chat Salon feature. Integrate it into your app's modules or homepage to fit your UI flow and business logic. You can also modify the source code for specific needs.
// Set user profile and initialize
String roomId = "xxx";
AUIVoiceRoom auiVoiceRoom = ChatRoomManager.getInstance().createVoiceRoom(roomId);
UserInfo userInfo = new UserInfo("xxx", "xxx");
userInfo.userName = currentUser.getName();
userInfo.avatarUrl = currentUser.getAvatar();
auiVoiceRoom.init(ChatEntryActivity.this.getApplicationContext(), ClientMode.VOICE_ROOM, VoiceRoomServerConstant.APP_ID, userInfo, ChatEntryActivity.this.im_token, new ActionCallback() {
@Override
public void onResult(int code, String msg, Map<String, Object> params) {
if(code == ChatRoomManager.CODE_SUCCESS) {
Log.v(TAG, "init room success");
} else {
Log.v(TAG, "init room fail:code:" + code + ",msg:" + msg );
}
}
});
// Join a room
RoomInfo roomInfo = new RoomInfo("xxx");
RtcInfo rtcInfo = new RtcInfo("xxx", "xxx");
auiVoiceRoom.joinRoom(roomInfo, rtcInfo, new ActionCallback() {
@Override
public void onResult(int code, String msg, Map<String, Object> params) {
Log.v(TAG, "join room:" + code + ",msg:" + msg + ",roomId:" + roomInfo.roomId);
}
});
Results
See the Demo experience.
FAQ
For questions about AUI Kits, contact us by joining our DingTalk group chat (ID: 106730016696).