Getting Started

This section outlines how you can set-up your project for success and begin using our Chat SDK for Android.

Initialisation

Before using the Chat SDK, you will need to create a new SDK instance with your API key. Please find your account API key via the Admin Panel. If you have trouble finding this, you can send our support team an email at developer@amity.co

class SimpleChatApp : Application() {

    override fun onCreate() {
        super.onCreate()

        EkoClient.setup("YOUR_API_KEY")
    }
}

Authentication

In order to use any Chat SDK feature, you must first register the current device with an userId. A registered device will be tied to the registered userId until the device is either proactively unregistered, or until the device has been inactive for over 90 days. A registered device will receive all the events messages belonging to the tied user.

An optional displayName can be provided, which will be used in standard push notifications (related to user's actions, such as when the new message is sent).

class HomeActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        EkoClient.registerDevice("userId 1")
                .displayName("John Doe")
                .build()
                .submit()
    }

}

The displayName is set only on the first time the device is registered, please follow your platforms necessary directions if you would like to rename this to something else.

Unregister

When the user logs out, you should explicitly unregister the user from the SDK as well. This prevents the current device from receiving unnecessary and/or restricted data.

EkoClient.unregisterDevice();

Devices

Each user can be registered, at the same time, to an unlimited number of devices. Amity's Chat SDK will automatically synchronize the user data across all registered devices. We will also automatically unregister any device that has not been connected to the server for more than 90 days.

When a device is unregistered due to inactivity, the SDK data on the device will be reset. You will need to re-register this device in order to connect to server again.

Connection Status

If you have any logic or UI around the connection status, you can observe the connectionStatus property on the EkoClient instance.

Since the Chat SDK automatically manages the network connection and queue up any requests in cases of bad connection, there should be little need to attach additional logic to this status. However the user may want to know the exact network status to determine if their actions will be performed in real-time, therefore this status is exposed.

// listen to connectionStatus event
client.on('connectionStatusChanged', ({ oldValue, newValue }) => {
  // handle changes
});

// stop listening to connectionStatus event once you are finished
client.removeAllListeners('connectionStatusChanged');\

Amity Social Cloud Sample App

Our Sample app adopts an open source framework that highlights how Amity Social Cloud SDK's can be implemented into application builds pragmatically.

With real life use-cases, we guide you through ways you can get started with building stellar applications for yourself and your clients and their users

Download the Android sample app

Last updated