Real-Time Audio Call

This section introduces how to quickly start an audio call with the audio SDK for Android.

1. Prerequisites

2. Development Environment Preparation

This section introduces how to create an Android project, integrate audio SDK to your project and add corresponding device permissions.

2.1 Create a Project

  1. Open Android Studio and click Start a new Android Studio project.
  2. Choose Phone and Tablet > Empty Activity, and then click Next.
  3. Enter the following contents:
  • Name: project name, for example, mouselive-android
  • Package name: Project package name, for example, com.jocloud.mouselive
  • Project location: Project saving path
  • Language: Programing language, for example, Java
  • Minimum API level: The minimum API level of the project
  1. Click Finish. Follow the on-screen instructions, if any, to install the plug-ins.

2.2 Add Library Files

  1. Edit outer file ild.gradle of the project and add library paths (both)
buildscript {
    repositories {
        maven { url " }

allprojects {
    repositories {
        maven { url "" }
  1. Edit file build.gradle in the application and add a specific SDK version.
	implementation "com.rtc.thunder:thunder:X.Y.Z" // For X.Y.Z, please fill in a specific SDK version number, such as 2.8.2.  
  1. Add the following line in the file to prevent obfuscating the code of the SDK.
-keep class com.rtc.thunder.** { *; } 

2.3 Add Project Permissions

To ensure SDK functions normally, add the following permissions into file AndroidManisfest.xml after the library is added.

    //Add permission
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    //Add software features
    <uses-feature android:name="" />
    <uses-feature android:name="" />
    <uses-feature android:name="android.hardware.microphone" android:required="true" />
    <uses-feature android:name="" />
    <uses-feature android:name="" android:required="true" />
    <uses-feature android:name="" android:required="true" />

3. Real-Time Audio Call

This section introduces how to use real-time voice call. The following chart shows the sequence of API calling during a voice call:

3.1 Create SDK Instance

Before calling audio/video APIs, create and initialize the object of ThunderEngine. To initialize ThunderEngine, call createEngine and input AppID and scenario ID.

// "appId"-AppID, which issued by the application developer
// "sceneId"-custom scenario ID, which is used for subdividing service scenarios; if unnecessary, set it to 0
// "thunderEventHandler"-callback object
thunderEngine = ThunderEngine.createEngine(context, appId, sceneId, thunderEventHandler);

3.2 Set Media Mode and Room Scenario Mode

Media modes for SDK include audio-only and audio/video. Call setMediaMode before joining the room, which is invalidated after joining the room and audio/video is the mode by default without being called otherwise.

// THUNDER_PROFILE_DEFAULT(0)	    audio/video mode by default
// THUNDER_PROFILE_NORMAL(1)	    audio/video mode (audio and video are both used)
// THUNDER_PROFILE_ONLY_AUDIO(2)	audio-only mode (for scenarios without video, to prioritize audio quality)

SDK can optimize by different methods in accordance with certain scenario of applications (such as communication mode or live streaming mode) and call setRoomMode to set room mode.

// THUNDER_ROOMCONFIG_LIVE(0)	live streaming mode, where quality is prioritized and delay is large. Applicable to audience scenarios.
//                              When an audience starts to publish and becomes an anchor, the mode changes to communication mode.
// THUNDER_ROOMCONFIG_COMMUNICATION(1)	communication mode is applicable for one-to-one communication and group conversation due to its low latency and smooth connection.
// THUNDER_ROOMCONFIG_MULTIAUDIOROOM(4)	voice chatroom mode is applicable for group voice chatroom due to its low latency and low bandwidth occupation.

3.3 Join a Room

After initialization, call joinRoom to join a room. Input the following parameters into this method:

  • token: Token for identifying user roles and permissions
  • roomName: Room name (unique for each AppId), supports only a combination of characters such as [A,Z],[a,z],[0,9],-,_, and the maximum size is 64 bytes.
  • uid: User ID, supports only a combination of characters such as[A,Z],[a,z],[0,9],-,_, and the maximum size 64 bytes.
thunderEngine.joinRoom(token, roomName, uid);

3.4 Publish Audio

After joining the room, call stopLocalAudioStream to start audio publishing and send local audio stream. Input the following parameters into this method:

  • stop: enable/disable sending local audios. The sending (disabled by default) can be normally enabled only if onJoinRoomSuccess callback is received.
// Enable local audio sending (false)

After joining the room, audio/video stream will be automatically subscribed. When other users in the channel publish/stop publishing, onRemoteAudioStopped is received.

3.5 Stop Publishing Audio

After joining the room, call stopLocalAudioStream to start audio publishing and send local audio stream. Upload the following parameters into this method:

  • stop: enable/disable local audio sending. The sending (disabled by default) can be normally enabled only if onJoinRoomSuccess callback is received.
// Disable local audio sending (true)

3.6 Exit a Room

Call leaveRoom to exit the current room. Whether in a call or not, this method can be called, and all resources related to conversation will be released after calling it.

// Exit the room

3.7 Destroy Instances

Call destroyEngine to release all resources used by SDK and user cannot call other methods in this SDK.

// Destroy SDK instance

4. API Reference

5. Notices

  • API return value: return 0 for success and return <0 for failure.

Was this page helpful?

Helpful Not helpful
Submitted! Your feedback would help us improve the website.