Initialize the SDK

You can initialize the SDK referring to this document.

Step 1: Prepare an SDKAppID.

Step 2: Pet the LogLevelEnum.

Step 3: PSet the SDK event listener.

Step 4: Pall initSDK to initialize the SDK.

Tips: By default, IM SDK logs on Android are stored in the /sdcard/tencent/imsdklogs/application package name directory for versions earlier than v4.8.50 and in the /sdcard/Android/data/package name/files/log/tencent/imsdk directory for v4.8.50 or later.

Starting from v4.7.1, the xlog module from WeChat is used to output IM SDK logs, which are compressed by default and must be decompressed by using the Python script.

To obtain the script for decompression, click Decode Log 27 (for Python 2.7) or Decode Log 30 (for Python 3.0).

In the Windows or macOS console, you can decompress log files by running the following command. After decompression, the file names end with "xlog.log", and you can use the text editor to open these files.

python imsdk_yyyyMMdd.xlog

If you receive the onUserSigExpired callback, the UserSig that you use for login has expired. In this case, you need to use a new UserSig to log in again. If you continue to use the expired UserSig, the IM SDK will be in an infinite login loop.

Parameter details

Parameter name Parameter type Required Platform Description
sdkAppID int yes All sdkAppID, the ID for the specific application, can get from IM Console.
loglevel LogLevelEnum yes All Log Level, referring to this document.
listener V2TimSDKListener yes All The listener.

Returned template


    code : int
    desc : String
    data : bool

Return value details

name type description
code int Request result: Error codes. 0 means success.
desc String The description of the error. It will be empty if success.
data bool The result of the initialization.

Code example

    int sdkAppID = 0;
    V2TimSDKListener sdkListener = V2TimSDKListener(
      onConnectFailed: (int code, String error) {
      onConnectSuccess: () {
      onConnecting: () {
      onKickedOffline: () {
      onSelfInfoUpdated: (V2TimUserFullInfo info) {
      onUserSigExpired: () {
      onUserStatusChanged: (List<V2TimUserStatus> userStatusList) {
    V2TimValueCallback<bool> initSDKRes =
        await TencentImSDKPlugin.v2TIMManager.initSDK(
      sdkAppID: sdkAppID, 
      loglevel: LogLevelEnum.V2TIM_LOG_ALL, 
      listener: sdkListener, 
    if (initSDKRes.code == 0) {

results matching ""

    No results matching ""