Home
/
Calls
/
Android

Make your first call

The Calls SDK adds call features to your client app with a few simple steps. To make your first call, do the following steps:


Step 1: Initialize the Calls SDK in your app

First, the SendBirdCall instance must be initialized when a client app is launched. Initialization is done by using the APP_ID of your Sendbird application in the dashboard. If the instance is initialized with a different APP_ID, all existing call-related data in a client app will be cleared and the SendBirdCall instance will be initialized again with the new APP_ID.

Note: The SendBirdCall.init() method must be called once across your Android client app. It is recommended to initialize the Chat SDK in the onCreate() method of the Application instance.

Light Color Skin
Copy
// Initialize SendBirdCall instance to use APIs in your app.
SendBirdCall.init(getApplicationContext(), APP_ID);

Step 2: Authenticate a user and add a registration token

To make and receive calls, authenticate a user to Sendbird server by using their user ID through the authenticate() method. To receive calls while an app is in the background or closed, a user’s registration token must be added to the server. A registration token can be added by passing it as an argument to a parameter in the authenticate() method when authenticating a user, or by using the SendBirdCall.registerPushToken() method after a user’s authentication has been completed.

Light Color Skin
Copy
// The USER_ID below should be unique to your Sendbird application.
AuthenticateParams params = new AuthenticateParams(USER_ID)
    .setAccessToken(ACCESS_TOKEN)
    .setPushToken(PUSH_TOKEN, isUnique);

SendBirdCall.authenticate(params, new AuthenticateHandler() {
    @Override
    public void onResult(User user, SendBirdException e) {
        if (e == null) {
            // The user has been authenticated successfully and is connected to Sendbird server.
            ...
        }
    }
});

Note: You can implement both the Chat and Calls SDKs to your client app. Two SDKs can work on the same Sendbird application for them to share users. In this case, you can allow Calls to retrieve a list of users in the client app by using the Chat SDK’s method or Chat API.


Step 3: Add an event handler

Add a device-specific SendBirdCallListener event handler using the SendBirdCall.addSendBirdCallListener() method. Once the event handler is added, responding to device events such as incoming calls can be managed as shown below:

Light Color Skin
Copy
SendBirdCall.addListener(UNIQUE_HANDLER_ID, new SendBirdCallListener() {
    @Override
    public void onRinging(DirectCall call) {
        ...

    }
});

Note: If a SendBirdCallListener event handler isn’t registered, a user can't receive an onRinging callback event, thus recommended to add this handler at the initialization of the app. Also, a SendBirdCallListener event handler is automatically removed when the app closes by default.


Step 4: Make a call

Initiate a call by providing the callee’s user id into the SendBirdCall.dial() method. Use the CallOptions object to choose initial call configuration, such as audio or video capabilities, video settings, and mute settings.

Light Color Skin
Copy
DialParams params = new DialParams(CALLEE_ID);
params.setVideoCall(true);
params.setCallOptions(new CallOptions());

DirectCall call = SendBirdCall.dial(params, new DialHandler() {
    @Override
    public void onResult(DirectCall call, SendBirdException e) {
        if (e == null) {
            // The call has been created successfully.
        }
    }
});

call.setListener(new DirectCallListener() {
    @Override
    public void onEstablished(DirectCall call) {
    }

    @Override
    public void onConnected(DirectCall call) {
    }

    @Override
    public void onEnded(DirectCall call) {
    }
});

Step 5: Receive a call

To receive an incoming call, a SendBirdCallListener event handler should already be registered in the callee’s client app. Accept or decline the call using the directCall.accept() or the directCall.end() method. If the call is accepted, a media session will automatically be established by the Calls SDK.

Light Color Skin
Copy
SendBirdCall.addListener(UNIQUE_HANDLER_ID, new SendBirdCallListener() {
    @Override
    public void onRinging(DirectCall call) {
        call.setListener(new DirectCallListener() {
            @Override
            public void onEstablished(DirectCall call) {
            }

            @Override
            public void onConnected(DirectCall call) {
            }

            @Override
            public void onEnded(DirectCall call) {
            }

            @Override
            public void onRemoteAudioSettingsChanged(DirectCall call) {
            }
        });

        call.accept(new AcceptParams());
    }
});