Voice Call
  • iOS
  • Android : Java
  • macOS
  • Windows
  • Linux
  • Web
  • WeChat Mini Program
  • Flutter
  • Electron
  • Unity3D
  • uni-app
  • React Native
  • Cocos2D
  • Introduction
  • Sample codes
  • Client SDKs
    • SDK downloads
    • Release notes
  • Getting started
    • Integrate the SDK
    • Implement a basic voice call
    • Use Tokens for authentication
  • Guides
    • Common audio config
    • Real-time messaging
    • Enhancing call quailty
    • Stream mixing
    • Playing media files
    • Playing Streams via URL
    • Voice Change/Reverb/Stereo
    • Local media recording
    • Advanced features
    • Quotas and Limits
  • Error codes
  • Server APIs
  • API Documents
  • FAQ
Sample Code

Guidelines for Running Sample Codes

ZEGOCLOUD no longer classifies environments into production environments and testing environments.

If you create your project in ZEGOCLOUD Admin Console on/before 2021-11-16, refer to the Testing environment deprecation to upgrade the SDK and adjust related codes.


  • Please ensure that the development environment meets the following technical requirements (the following instructions are based on macOS development computers as examples):

    • Android Studio 2020.3.1 or above.
    • Android SDK 30 and Android SDK Platform-Tools 30.x.x or above.
    • Android 4.4 or above and support audio and video (recommended to use a real device), if it is a real device, please enable the "Allow debugging" option.
    • The Android device and macOS computers are connected to the Internet.
  • A project has been created in ZEGOCLOUD Admin Console and a valid AppID have been applied.

  • When you compile the sample code for the first time, there is no corresponding dependent library or build tool, "Android Studio" will download the sample code by itself, which may take a long time, please be patient.
  • It is recommended to download a specific Gradle and the required dependent libraries. Please make sure that the development computer is connected to the Internet and can be accessed normally https://services.gradle.org. The relevant versions of Gradle used in the sample code are as follows:
    • Gradle: 6.7.1 (in the "project/gradle/wrapper/gradle-wrapper.properties" file).
    • Android Gradle plugin: 4.2.0 (in the "project/build.gradle" file).

For the version dependency between Android Gradle plugin, Gradle, and SDK Tool, please see: Android Gradle plugin release notes

Run the Sample Codes

  1. Find the Android Studio software icon on the development computer.

    How to install Android Studio on the development computer
    • Method 1: Log in to Android Studio official website to download and install Android Studio and its related SDK Tools. Due to domestic operator network restrictions and other reasons, the developer needs to ensure that the machine can connect to the website. If you cannot access it, it is recommended to choose method 2.
    • Method 2: Use a search engine to search for "Android Studio download", "Android Studio installation" and "Android Studio SDK Tools installation", find downloadable source websites, and install related software and tools.
  2. Open Android Studio, and click "Open an Existing Project".

  3. In the unzipped example source code folder, select the ZegoExpressExample folder and click "Open" to open it.


  4. (Optional) Integrated SDK.

Choose to integrate the SDK according to the download method
  • Download: The sample source code downloaded from the compressed package already contains the SDK package, please skip this step.
  • GitHub: The SDK package is missing from the sample source code downloaded from Github. You need to download SDK first, and Copy the decompressed jar package and so to the ./main/libs/ directory.
  1. The downloaded sample code lacks the appID, userID and token required for SDK initialization, so you need to modify the "KeyCenter.java" file in the "./KeyCenter/src/main/java/im/zego/keycenter" directory.

    // Developers can get appID from admin console.
    // https://console.zego.im/dashboard
    // for example:
    //     private long _appID = 123456789L;
    private long _appID = ;
    // Developers should customize a user ID.
    // for example:
    //     private String _userID = "zego_benjamin";
    private String _userID = "";
    // Developers can get token from admin console.
    // https://console.zego.im/dashboard
    // Note: The user ID used to generate the token needs to be the same as the userID filled in above!
    // for example:
    //     private String _token = "04AAAAAxxxxxxxxxxxxxx";
    private String _token = "";
  2. Select a real Android device (recommended) or emulator that has been connected to the Internet. When the device has successfully turned on the developer mode and USB debugging function, you can see the Android Studio as shown below:


    Change to the following figure:


    Description The Android Studio software has successfully connected to the Android device, and the sample code can be run on the device.

    • When the development computer is connected to an Android device, most devices will pop up a prompt. Different Android manufacturers have different prompts. You can select the USB mode according to the situation.
    • When the Android device is connected to the development computer, you need to enable the developer mode and USB debugging function on the device according to the situation (Android devices of different manufacturers have different opening methods). The specific opening method can be searched by a search engine. For example: There is currently a "xxx" device that has not enabled the developer mode and USB debugging function. You can search for "xxx Open Developer Mode" in the search engine to view the specific opening tutorial.
  3. Click the Run button on the Android Studio software to compile and run the sample code.


If there is a problem during operation, please contact ZEGO technical support.

Experience Real-time Audio and Video Functions

We recommend you run your project on a real device. If your app runs successfully, you should hear the sound and see the video captured locally from your device.

To test out the real-time audio and video features, visit the ZEGO Express Web Demo, and enter the same AppID, Server and RoomID to join the same room. If it runs successfully, you should be able to view the video from both the local side and the remote side, and hear the sound from both sides as well.

In audio-only scenarios, no video will be captured and displayed.


  1. What should I do if it reports "illegal start of expression" when running the downloaded sample code in Android Studio?

    Because AppID do not have specific values ​​in the downloaded sample source code, please refer to step 5 in the Run the Sample Codes chapter of this article for processing.