Initialize client

Before you can place a call, you need to initialize Client SDK. Add this line at the end of onCreate method of MainActivity class:

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

Set connection listener

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

client.setConnectionListener((connectionStatus, connectionStatusReason) -> runOnUiThread(() -> connectionStatusTextView.setText(connectionStatus.toString())));

Now client needs to authenticate to the Vonage servers. The following additions are required to onCreate method inside MainActivity. Replace the ALICE_TOKEN with the JWT token, you obtained previously from Vonage CLI:


Build and Run

Press the Ctrl + R keys to build and run the app again. After successful login you will see CONNECTED text: