The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Android

Last updated: 2024-12-19 17:35:13

This document describes how to quickly integrate the Tencent Cloud TEduBoard SDK into your project. If you are using the Interactive Classroom solution, please go to Interactive Classroom Integration.

Development Environment

Android Studio 2.0+
Android 4.2 (SDK API 17) and above

Integrate TEduBoard SDK

You can choose to use Gradle for automatic loading or manually download the AAR and import it into your project. Since the TEduBoard SDK internally uses TIMSDK as the internal signaling channel, you also need to automatically or manually add TIMSDK dependencies.

Automatic Loading (AAR)

TEduBoard SDK and TIMSDK have been released to the Maven Central repository. You can automatically download and update them by configuring Gradle.


1. Add SDK dependencies

dependencies {
implementation 'com.tencent.edu:TEduBoardSdk:latest.release'
implementation 'com.tencent.imsdk:imsdk:latest.release'
}

2. Sync the SDK

Click Sync Now. If you have no problem connecting to Maven Central, the SDK will be downloaded and integrated into your project automatically.

Manual Download (AAR)

If you have a problem connecting to Maven Central, you can manually download the SDK and integrate it into your project.

1. Download the SDK

Click to download the latest version of TEduBoard SDK. Go to Chat to download TIMSDK.

2. Import the SDK

Copy the downloaded AAR file to the app/libs directory of your project.


3. Specify the local repository path

Add flatDir in build.gradle in the project root directory to specify the local repository path.


4. Add SDK dependencies

Add the code to reference the AAR package in app/build.gradle.
dependencies {
implementation (name: "TEduBoardSdk-release", ext: "aar")
implementation (name: "imsdk-plus-6.6.3002", ext: "aar") // Please use the latest version of IM. For more details, please refer to the IM changelog at https://cloud.tencent.com/document/product/269/1606
implementation 'com.tencent.edu:TIWLogger:1.0.1.76'
implementation 'com.tencent.edu:TIWCache:1.0.0.91'
}


5. Sync the SDK

Click Sync Now to complete the TEduBoard SDK integration.

Configuring Permissions

To configure app permissions in AndroidManifest.xml, the TEduBoard SDK requires the following permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Using TEduBoard SDK

1. Create whiteboard controller
Use the following code to create and initialize the whiteboard controller:
// Create and initialize the whiteboard controller
// (1) Authentication configuration
TEduBoardController.TEduBoardAuthParam authParam = new TEduBoardController.TEduBoardAuthParam(sdkAppId, userId, userSig);

// (2) Whiteboard default configuration
TEduBoardController.TEduBoardInitParam initParam = new TEduBoardController.TEduBoardInitParam();
mBoard = new TEduBoardController(context);

// (3) Add whiteboard event callback and implement the TEduBoardCallback interface
TEduBoardCallback callback = new TEduBoardController.TEduBoardCallback();
mBoard.addCallback(callback);

// (4) Perform initialization
mBoard.init(authParam, classId, initParam);

Among them sdkAppId, userId, userSig, and classId are parameters that need to be filled in by you.
Note
1. Please perform the initialization operation in the main process. If your app uses multiple processes, please avoid repeated initialization.
2. Due to the internal call of HarmonyOS's evaluatejavascript being changed to asynchronous main thread invocation, the whiteboard GET interface waiting on the main thread and synchronously returning results will cause a deadlock. With the premise of continuing to use the GET interface in a synchronous way, the SDK can no longer avoid this internally. Please update to version 2.8.2 or above and use a child thread to call the whiteboard GET related interfaces externally (as shown in the example below). We will optimize the GET related interfaces asynchronously in the future.
new Thread(new Runnable() {
@Override
public void run() {
TEduBoardFileInfo info = board.getFileInfo(fileId);
}
}).start();
2. Listening to whiteboard key events
Listen to whiteboard events within the TEduBoardCallback onTEBError and onTEBWarning callback methods of the whiteboard event callback interface.
/**
* Whiteboard error callback
* Events that must be monitored
*
* @param code Error Code
* @param msg //Error message, encoded in UTF8
*/
void onTEBError(int code, String msg);

/**
* Whiteboard warning callback
* @param code Warning Code
* @param msg //Warning message, encoded in UTF8
*/
void onTEBWarning(int code, String msg);
3. Retrieve and Display Whiteboard Window
In the onTEBInit callback method, use the following code to retrieve and display the whiteboard view:
// (1) In the layout XML file of the Activity, use FrameLayout as a placeholder for the future board view.
<FrameLayout
android:id="@+id/board_view_container"
android:layout_width="match_parent"
android:layout_height="200dp"/>
// (2) Retrieve the whiteboard view
View boardview = mBoard.getBoardRenderView();
// (3) Add to the Parent View
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
FrameLayout container = findViewById(R.id.board_view_container);
container.addView(boardview, layoutParams);
All SDK callbacks are executed on the Main Thread, so you can directly perform UI operations in the callback.
4. Whiteboard Data Synchronization
During the use of the whiteboard, data synchronization (e.g., graffiti data) needs to be performed among different users. The SDK uses IMSDK as the signaling channel by default. You need to implement the initialization, login, and group joining operations of IMSDK yourself to ensure IMSDK is within the specified group when the whiteboard is initialized.
Step 1: Initialize IMSDK

V2TIMSDKConfig timSdkConfig = new V2TIMSDKConfig();
boolean result = V2TIMManager.getInstance().initSDK(context, sdkAppID, timSdkConfig);

If you have other services using IMSDK and expect the lifecycle of IMSDK to be consistent with the lifecycle of the App, please initialize IMSDK in the onCreate method of the Application. Otherwise, please initialize IMSDK before logging in and deinitialize IMSDK after logging out.
Step 2. Log in to IMSDK
TIMGroupManager.getInstance().login(userId, userSig, new TIMCallBack() {
@Override
public void onSuccess(String s) {

}

@Override
public void onError(int errCode, String errMsg) {
// Failed to create IM group
});

V2TIMManager.getInstance().login(userId, userSig, new V2TIMCallback() {
@Override
public void onSuccess() {
// Login succeeded
}

@Override
public void onError(int errCode, String errMsg) {
// Login failed
}
});

Step 3. Join the group
Join the group where the whiteboard is located after successfully logging in to IMSDK.
V2TIMManager.getInstance().joinGroup(classId, "board group" + classId, new V2TIMCallback() {
@Override
public void onSuccess() {
// Successfully joined the group
}

@Override
public void onError(int i, String s) {
// Failed to join the group
}
});
If the IM group does not exist, please create the group first.
V2TIMManager.getGroupManager().createGroup(groupInfo, null, new V2TIMValueCallback<String>() {
@Override
public void onError(int errCode, String errMsg) {

}

@Override
public void onSuccess(String s) {

}
});
Note
1. It is recommended to use the IM REST API to create groups in advance in the backend.
2. Different group types, group features, and the number of members vary. For details, please refer to the IM group system.
5. Terminate the whiteboard
After calling the unInit method, the whiteboard will be completely terminated internally and billing will stop. Please ensure this interface is called.
mBoard.uninit();
If you use IMSDK as the signaling channel, decide whether to exit the group, log out, and deinitialize according to the needs of your business.
Step 1: Exit the group
V2TIMManager.getInstance().quitGroup(classId, new V2TIMCallback() {
@Override
public void onSuccess() {

}

@Override
public void onError(int i, String s) {

}
});
Step 2: Log out of IMSDK
// IM log out
public void logout(final IMCallBack callBack) {
V2TIMManager.getInstance().logout(new V2TIMCallback(){
@Override
public void onSuccess() {

}

@Override
public void onError(int errCode, String errMsg) {

}
});
}
Step 3: Deinitialize IMSDK
V2TIMManager.getInstance().unInitSDK();
If you have other businesses using IMSDK and you wish IMSDK's lifecycle to be consistent with the App's lifecycle, you do not need to call this interface.