Skip to main content

Make your first call

This tutorial shows how to build a minimal calling integration in an Android app by using the public APIs currently exposed from ai.nexconn.call.api.

Prerequisites

  • Android minSdkVersion: 21
  • Android compileSdk / targetSdk: 35
  • Java 11 build configuration
  • A working Chat SDK initialization and connection flow

Step 1: Add dependencies and project configuration

1. Add SDK dependencies

Based on the current repository configuration, the Android module uses these Maven coordinates:

  • groupId: ai.nexconn.chat
  • artifactId: call

Example:

gradle
repositories {
maven { url "https://maven.nexconn.ai/repository/maven-releases/" }
}

dependencies {
implementation "ai.nexconn.chat:call:<version>"
implementation "ai.nexconn.chat:chat:<version>"
// Optional push SDKs
implementation "ai.nexconn.chat:push-fcm:<version>"
implementation "ai.nexconn.chat:push-hms:<version>"
}

Use a Nexconn Chat SDK version that matches your Call SDK package, and complete Chat initialization and connection first.

2. Configure permissions

  1. Declare all required permissions in AndroidManifest.xml.

    xml
    <!-- Allows the app to access network connections -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- Allows the app to query network connection state -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <!-- Allows the app to query Wi-Fi and hotspot state -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <!-- Allows the app to use the camera -->
    <uses-permission android:name="android.permission.CAMERA" />
    <!-- Allows the app to record audio -->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <!-- Allows the app to modify audio settings -->
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <!-- Allows the app to read phone state -->
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  2. If your app supports Android 6.0 (API level 23) or later, request CAMERA and RECORD_AUDIO at runtime when the user starts or accepts a call. For details, see the Android documentation for runtime permissions and the request permission workflow.

3. Configure code shrinking

If you build with minifyEnabled true, add the following rules to your module ProGuard file:

Groovy
-keepattributes Exceptions,InnerClasses
-keepattributes Signature

# Chat SDK
-keep class ai.nexconn.chat.** {*;}
-keep class io.rong.** {*;}
-keep class cn.rongcloud.** {*;}
-keep class * implements io.rong.imlib.model.MessageContent {*;}
-dontwarn io.rong.push.**
-dontnote com.google.android.gms.gcm.**
-dontnote io.rong.**

# Call SDK
-keep public class cn.rongcloud.rtc.** {*;}
-keep public class cn.rongcloud.rtclib.** {*;}
-keep public class cn.rongcloud.calllib.** {*;}
-keep public class cn.rongcloud.callplus.** {*;}
-keep class ai.nexconn.call.** {*;}

-ignorewarnings

Step 2: Install and initialize the Call SDK

Use this initialization order:

  1. Call NCCallEngine.install() before Chat SDK initialization.
  2. Initialize and connect the Chat SDK.
  3. After Chat is connected, call NCCallEngine.getInstance().initialize(...).
Java
// 1. Call once during app startup, before NCEngine initialization
NCCallEngine.install();

// 2. Initialize NCEngine
InitParams params = new InitParams(context, "your-app-key");
params.setLogLevel(LogLevel.DEBUG);
params.setAreaCode(AreaCode.SINGAPORE);
params.setEnablePush(true);
NCEngine.initialize(params);

// 3. Connect the Chat SDK
ConnectParams params = new ConnectParams("user-token");
NCEngine.connect(params, new ConnectHandler() {
@Override
public void onResult(String userId, NCError error) {
... ...
}
});

// 4. Initialize the Call SDK after Chat is connected
NCCallEngine engine = NCCallEngine.getInstance();

INCCallInitOptions options = CallInitOptionsImpl.Builder.create()
.pubLowResolutionStream(true)
.build();

NCCallResultCode initCode = engine.initialize(context, options);

If initialize(...) returns NCCallResultCode.CHAT_NOT_CONNECTED, the Chat SDK is not connected yet.

Step 3: Register listeners

Register the call event listener before Chat connects so that you can receive restored call events or offline incoming calls as early as possible.

Java
NCCallEngine engine = NCCallEngine.getInstance();

engine.setCallEventsListener(new INCCallEventsListener() {
@Override
public void onCallReceived(INCCallSession callSession, String extra) {
// Incoming call received
}

@Override
public void onCallConnected(INCCallSession callSession) {
// Call connected
}

@Override
public void onCallEnded(INCCallSession session, NCCallEndReason reason) {
// Call ended
}
});

engine.setAPIResultListener(new INCCallAPIResultListener() {
@Override
public void onStartCall(NCCallCode code, String callId, List<INCCallUser> busyUsers) {
}

@Override
public void onAcceptCall(NCCallCode code, String callId) {
}

@Override
public void onEndCall(NCCallCode code, String callId) {
}
});

Step 4: Prepare local and remote video views

Before you start a video call, create the local and remote render views:

Java
NCCallLocalVideoView localView = new NCCallLocalVideoView(context);
localView.setScalingType(NCCallRenderMode.FILL);

NCCallRemoteVideoView remoteView =
new NCCallRemoteVideoView(context, remoteUserId, false);
remoteView.setScalingType(NCCallRenderMode.FILL);

NCCallEngine engine = NCCallEngine.getInstance();
engine.setVideoView(localView);
engine.setVideoView(Collections.singletonList(remoteView));

Step 5: Start a call

Java
NCCallEngine engine = NCCallEngine.getInstance();

engine.startCall(
Collections.singletonList(remoteUserId),
NCCallType.SINGLE,
NCCallMediaType.VIDEO
);

For an audio-only call, change mediaType to NCCallMediaType.AUDIO.

Step 6: Accept or end the call

On the callee side, call the following APIs after onCallReceived(...):

Java
String callId = callSession.getCallId();

// Accept the call
NCCallEngine.getInstance().acceptCall(callId);

// End or reject the call
NCCallEngine.getInstance().endCall(callId);

Step 7: Control devices during the call

After the call is connected, control audio and video devices as needed:

Java
NCCallEngine engine = NCCallEngine.getInstance();

engine.enableCamera(true);
engine.enableMicrophone(true);
engine.enableSpeaker(true);
engine.switchCamera();

Next steps