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

  1. Open your project in Android Studio and switch to the Project view.

  2. In the root build.gradle, declare the Nexconn Maven repository:

    Use the setup that matches your Gradle plugin version:

    Open the root build.gradle file and add:

    Groovy
    allprojects {
    repositories {
    ...

    mavenCentral()
    }
    }
  3. In your app-level build.gradle, add the Nexconn SDK as a dependency. Replace x.y.z with the latest version from the Maven repository.

    Groovy
    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.

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. Initialize the Call SDK, call NCCallEngine.initialize(...).
Java
// 1. Call once during app startup, before NCEngine initialization
NCCallEngine.install();

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

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

// 4. Initialize the Call SDK.
NCCallInitParams callInitParams = new NCCallInitParams(context);
callInitParams.pubLowResolutionStream(true);

NCCallEngine.initialize(callInitParams);

Make sure the Chat SDK is already connected before users place or receive calls; otherwise later call APIs can return NCCallCode.CHAT_DISCONNECTED.

Step 3: Register handlers

Register the call event handler 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.setCallEventHandler(new NCCallEventHandler() {
@Override
public void onCallReceived(NCCallReceivedEvent event) {
// Incoming call received
}

@Override
public void onCallConnected(NCCallConnectedEvent event) {
// Call connected
}

@Override
public void onCallEnded(NCCallEndedEvent event) {
// Call ended
}

... ...

});

engine.setAPIResultHandler(new NCCallAPIResultHandler() {
@Override
public void onStartCall(NCCallStartCallResult result) {
}

@Override
public void onAcceptCall(NCCallAcceptCallResult result) {
}

@Override
public void onEndCall(NCCallEndCallResult result) {
}

... ...

});

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 NCCallLocalVideoSurfaceView(context);
localView.setRenderMode(NCCallRenderMode.FILL);

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

//TODO: add the created localView and remoteView to your own UI layout

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

Step 5: Start a call

Java
NCCallStartCallParams params = new NCCallStartCallParams(
Collections.singletonList(remoteUserId),
NCCallType.SINGLE,
NCCallMediaType.AUDIO_VIDEO
);
params.setPushConfig(pushConfigs); // optional: android&iOS push config
params.setExtra(extra); //optional: extra content sent to receivers

NCCallEngine engine = NCCallEngine.getInstance();
engine.startCall(params);

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
NCCallReceivedEvent event = ...; // from onCallReceived callback
String callId = event.getCallSession().getCallId();

// Accept the call
NCCallAcceptCallParams acceptParams = new NCCallAcceptCallParams(callId);
NCCallEngine.getInstance().acceptCall(acceptParams);

// End or reject the call
NCCallEndCallParams endParams = new NCCallEndCallParams(callId);
NCCallEngine.getInstance().endCall(endParams);

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