Initialize the client

NexmoClient is the main class used to interact with Android-Client-SDK. Prior to usage, you have to initialize the client by providing an instance of the Android Context class.

At the top of the MainActivity class define client property that will hold the reference to the client and otherUser property that will hold the name of 2nd user (the user that call will be made to):

private NexmoClient client;
private String otherUser = "";

Locate the onCreate method in the MainActivity class and initialize NexmoClient using the builder:

override fun onCreate(savedInstanceState: Bundle?) {

    // ...

    client = new NexmoClient.Builder().build(this);

IDE will display a warning about the unresolved reference:

Put caret on the red text and press Alt + Enter to import the reference.

Now below client initialization code add connection listener to monitor connection state:

client.setConnectionListener((connectionStatus, connectionStatusReason) -> {
    runOnUiThread(() -> {

    if (connectionStatus == ConnectionStatus.CONNECTED) {
        runOnUiThread(() -> {

The above listener allows to determine that that user has logged in successfully. After successful login based on the user name, the app will show start call button (for Alice) or Waiting for incoming call text (for Bob).

Now in the MainActivity class add helper method that hides all UI items:

private void hideUI() {
    LinearLayout content = findViewById(;

    for (int i = 0; i < content.getChildCount(); i++) {
        View view = content.getChildAt(i);

Finally fill the body of two methods to allow user login. Please make sure to replace ALICE_JWT and BOB_JWT with the JWTs you created during a previous step:

private void loginAsAlice() {
    otherUser = "Bob";


private void loginAsBob() {
    otherUser = "Alice";


NOTE Expiry time for the token was set to 6 hours so you will need to generate a new one if it is too old.

Build and Run

Press Ctrl + R buttons to build and run the app.

After successful user login you will see waiting for incoming call text and make a call button:

Make a call
Make a call