Registered
First go to the cloud website to register a Development Account address here
Download
Then download the Cloud Development SDK address here
-
Demo source for the official sample demo, without modification, direct operation can successfully see the relevant features of the cloud
-
The SDK is divided into two parts: the Cloud Im Interface component (IMKITHT) and the cloud IM Communication capability Library (IMLIB)
Create an App
Go to the cloud developer platform to create an app where Android needs to be aware
- app identity-package name here is the package name for the Android project, as the package name for the following code is Io.rong.imkit.demo
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="io.rong.imkit.demo">
- Appkey-app Key Here is the value of the APP key that needs to be declared in the manifest file, the development phase uses the development environment (test environment), the development should be switched to the production environment (the online environment), simple examples such as the following
<meta-data android:name="RONG_CLOUD_APP_KEY" android:value="e7x8xycsx6flq" />
Project configuration
-
Add a declaration to App_key
-
If you are developing with Imkit, modify the value of all its android:host to the package name of the development app
-
If you are developing with Android studio, remember to add references to so files
Writing code
- Initialization, it is recommended to put it in the oncreate of application.
RongIM.init(this);
-
Get token, need developer server side support, if only for testing development, can go to the Cloud developer platform Select API Debugging-User Service-Get token for debugging development
-
Connect the cloud, get token and connect to the cloud server
//Here directly hardcode to token assignment, please replace it with your own token. String token ="mkmykqtsf7andinwafmnz7nxkilev3x0+ccrboxmtoapmvqjmathviwrepifq0gutu9jelqqsckv4ahfjcakgq==";//Connect to a cloud server. Rongim.connect (token,NewRongimclient.connectcallback () {@Override Public void onsuccess(String s) {//The connection is processed successfully here. LOG.D ("Connect:","Login successfully."); }@Override Public void OnError(ErrorCode ErrorCode) {//Handle connection errors here. LOG.D ("Connect:","Login failed."); } });
- When the server connection is successful, you can call the various chat interfaces of the cloud.
Cloud IM development Preparation (Android)