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

Compatibility

We are always working to enhance our existing SDKs. As a result, the minimum compatibility may vary for our previous version releases. Below is the compatibility list for our latest Chat SDK release. For a complete compatibility history of any given Chat SDK version, you may refer to our changelogs.
  • OKHTTP - 3.10.0
  • Retrofit - 2.4.0
  • Android Paging Data Library - 3.0.0
  • Room - 2.3.0
  • Kotlin-std-lib - 1.3.72

Initialization

Before using the Chat SDK, you need to create a new SDK instance with your API key. Please find your account API key in Amity Social Cloud Console.
After logging in Console:
  1. 1.
    Click Settings to expand the menu.
  2. 2.
    Select Security.
  3. 3.
    In the Security page, you can find the API key in the Keys section.
API key in Security page
If you have trouble finding this, you can post in our community forum at community.amity.co so our support team can assist you.
1
class ChatApp : Application() {
2
3
override fun onCreate() {
4
super.onCreate()
5
6
AmityCoreClient.setup(
7
apiKey = "apiKey",
8
httpEndpoint = AmityRegionalEndpoint.EU, // optional param, defaulted as SG region
9
socketEndpoint = AmityRegionalEndpoint.EU // optional param, defaulted as SG region
10
)
11
}
12
}
Copied!

Specify Endpoints Manually (Optional)

You can specify endpoints manually via optional parameters. API endpoints for each data center are different so you need to adjust the endpoint accordingly.
We currently support multi-data center capabilities for the following regions:
Region
Endpoint
Endpoint URL
Europe
AmityRegionalEndpoint.EU
api.eu.amity.co
Singapore
AmityRegionalEndpoint.SG
api.sg.amity.co
United States
AmityRegionalEndpoint.US
api.us.amity.co

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 session has expired. A registered device will receive all the events 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).
An authToken can be provided, which will be used for authentication. Should you choose to use insecure settings on your network, this parameter can be ignored. For more info on how to configure secure settings and obtain authToken, refer to our Security page.
1
class HomeActivity : AppCompatActivity() {
2
3
override fun onCreate(savedInstanceState: Bundle?) {
4
super.onCreate(savedInstanceState)
5
6
AmityCoreClient.registerDevice("userId 1")
7
.displayName("John Doe") // optional
8
.authToken("token") // optional
9
.build()
10
.submit()
11
.subscribe()
12
}
13
14
}
Copied!
The displayName is set only on the first time the device is registered. Please follow your platform's 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.
1
AmityCoreClient.unregisterDevice();
Copied!
Unregistering a device is a synchronous operation. Once theunregisterDevice method is called, the SDK disconnects from the server and wipes out user session.

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 to connect to server again.

Connection Status (Beta)

If you have any logic or UI around the WebSocket connection status, you can observe the AmityConnectionState property on the AmityCoreClient instance.
Chat SDK automatically manages the WebSocket connection and queues up any requests in cases of bad connection. There should be little need to attach additional logic to this status.
This status is exposed so you can check the WebSocket connection state and determine if your tasks are performed in real-time.
1
AmityCoreClient.getConnectionState()
2
.subscribe {
3
when (it) {
4
AmityConnectionState.DISCONNECTED -> {
5
print("disconnected")
6
}
7
AmityConnectionState.CONNECTING -> {
8
print("connecting")
9
}
10
AmityConnectionState.RECONNECTING -> {
11
print("reconnecting")
12
}
13
AmityConnectionState.CONNECTED ->{
14
print("connected")
15
}
16
AmityConnectionState.FAILED -> {
17
print("failed")
18
}
19
}
20
}
Copied!
This feature is still in beta version. Further enhancements to this functionality may be done in the future releases.

Amity Social Cloud Developer Kits

Check out our Amity Social Cloud UI Kits and Template Apps.
  • UI Kits Our UI Kits include user interfaces to enable fast integration of standard Amity Chat and Amity Social features into new or existing applications.
  • Template Apps Our Template Apps are ready-made template applications to kickstart your own Amity Social Cloud project.
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
Last modified 3d ago