Setup

Initialize the SDK

Before using the SDK, you will need to initialize the SDK with your API key. Please find your account API key in the admin panel. The ideal place to do this is on application startup, in onCreate() method of Application class.

class SimpleChatApp : Application() {
override fun onCreate() {
super.onCreate()
EkoClient.setup("YOUR_API_KEY")
}
}

Authentication

In order to use any SDK feature, you must first register the current device with an userId. A device registered with an userId will be permenantly tied to that userId until you explicitly unregister the device, or until the device has been inactive for more than 90 days. A device registered with a sepecific userId will receive all messages belonging to that user.

Additionally, an optional displayName can be provided if you wish to have this user identified in push notifications.

class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EkoClient.registerDevice("userId 1")
.displayName("John Doe")
.build()
.submit()
}
}

Unregister

In the event that your user logs out, you should explicitly unregister the user from the SDK as well, to prevent the current device from receiving any unnecessary or restricted data.

EkoClient.unregisterDevice();

Devices

Each user can be registered to an unlimited number of devices. Which means that you can use the same userId on multiple devices: Eko will automatically synchronize the user’s data on all registered devices. Eko 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.