Run the Android demo

更新时间:
复制 MD 格式

This topic describes how to run the Android demo.

Prerequisites

You have obtained your authentication information from the console. For more information, see Access tools.

Note The token obtained from the console is for development and testing only. Using this token in a production environment poses a security threat. For production environments, you must set up your own server to generate tokens and use the HTTPS protocol. For more information, see Generate a token on the server-side.

Environment requirements

Make sure that the demo runs on a physical device with Android 4.4 or later.

Procedure

  1. Download and decompress the software development kit (SDK) and sample code. For more information, see SDK download.
  2. Add the ApsaraVideo Real-time Communication (RTC) SDK to the libs folder of the sample code. If the libs folder does not exist, create it.
    lib directory
  3. Open the AliRtcChatActivity.java file and configure the authentication parameters.
    Note For information about how to generate authentication parameters, see Generate a token.
            private void joinChannel() {
            if (mAliRtcEngine == null) {
                return;
            }
            AliRtcAuthInfo userInfo = new AliRtcAuthInfo() ;
            userInfo.setAppid("zwdm****");
            userInfo.setNonce("AK-d8847d08-c8b3-4800-84e3-7f6c4d65f96d");
            userInfo.setGslb(new String[]{"https://rgslb.rtc.aliyuncs.com"});
            userInfo.setTimestamp(1589379613);
            userInfo.setToken("e48d39484c91a26****");
            userInfo.setConferenceId("1234");
            userInfo.setUserId("testId");
    
            // Join a channel. You must provide the authentication information and a username.
            mAliRtcEngine.joinChannel(userInfo,"username");
        }
  4. Run the demo.

    After the demo starts, the audio and video call interface appears and displays the local preview view. The demo automatically joins the channel and waits for other users to join.

    Android Demo

    If other users are in the channel, you can have a real-time audio and video call.

    Successful run