Basic: Making a Voice call

Basic: Making a Voice call

Getting Started

You can download either the Agora Voice SDK or Video SDK to enable a voice call.

Agora recommends downloading the Video SDK, which includes both voice and video functions for more flexibility. You can:

  • Disable the video function if you only need the voice function, or
  • Enable the video function if you need both.

Step 1: Prepare the Environment

  1. Download the Video SDK.
  2. Hardware and software requirements:
    • Android 4.1 and later devices with audio and video support
    • Android SDK API 16 or later
    • Android Studio 2.0 or later
  3. Before accessing Agora’s services, make sure that you have connected to the ports and whitelisted the domains as specified in Firewall Requirements .

Step 2: Add the SDK

  1. Copy the following libraries from the libs folder according to your needs.

    • agora-rtc-sdk.jar (mandatory)
    • armeabi-v7a/
    • x86/
    • arm64-v8a
    • include

    Note

    When you copy the libraries to the libs folder in the targeted path, if there is any Chinese character in the path, the sample code will not be compiled successfully, and will display random ASCII code in the error message.

  2. Put the required libraries in the correct libs path according to the settings in the build.gradle file.

    ../_images/android_library.png
  3. Specify the directory of the so file in the build.gradle file as the path of the abovementioned libs folder.

    ../_images/android_so.png

Step 3: Configure the NDK

If the following error displays, it means that the NDK is not installed.

../_images/android6.png

Download the NDK from the Android developer website, and put it in the Android location, for example,

../_images/android7.png

Step 4: Add the Permissions

The following permissions are required in the AndroidManifest.xml file for your application when deployed:

  • <uses-permission android:name=”android.permission.INTERNET” />
  • <uses-permission android:name=”android.permission.RECORD_AUDIO” />
  • <uses-permission android:name=”android.permission.CAMERA” />
  • <uses-permission android:name=”android.permission.MODIFY_AUDIO_SETTINGS” />
  • <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />

Step 5: Synchronize with the Project Files

Click Sync Project With Gradle Files until the synchronization is complete.

../_images/android9.png

Step 6: Obfuscate the Code

Add the following line to obfuscate the code:

-keep class io.agora.**{*;}

Scenario 1: Making a Voice Call

  1. Get an App ID, refer to Getting an App ID.
  2. Initialize RtcEngine, and fill in the App ID, refer to Create an RtcEngine Object (create).
private void initializeAgoraEngine() {
    try {
        mRtcEngine = RtcEngine.create(getBaseContext(), getString(R.string.agora_app_id), mRtcEventHandler);
    } catch (Exception e) {
        Log.e(LOG_TAG, Log.getStackTraceString(e));

        throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
    }
}
  1. Join a channel, refer to Join a Channel (joinChannel).
private void joinChannel() {
    mRtcEngine.joinChannel(null, "demoChannel1", "Extra Optional Data", 0); // if you do not specify the uid, we will generate the uid for you
}
  1. Hang up/End a call, refer to Leave a Channel (leaveChannel).
private void leaveChannel() {
    mRtcEngine.leaveChannel();
}

Scenario 2: Implementing other Functions

The following functions can be implemented in a voice call:

Agora will provide the API call sequences and sample code for the following functions in the future. For now, see Voice Call API:

  • Text messages
  • Control voice; for example, mute or unmute