Kotlin

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.

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

val client = 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(() -> connectionStatusTextView.setText(connectionStatus.toString()));
});

Finally add the code to login the user. Please make sure to replace ALICE_JWT with the JWT you created during a previous step:

client.login("ALICE_JWT")

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 the Ctrl + R keys to build and run the app again. After successful login you will see CONNECTED text:

Connected
Connected