With CONTUS MirrorFly Chat SDK for Android, you can easily add real-time chat features to your client app within 30 minutes.
Through our client SDK, you can initialize and configure chat into your app with minimal efforts.
Note : If you're looking for the fastest way to build your app’s UI with MirrorFly Chat SDKs, you can use our sample apps. To get our sample apps, click here
The requirements for chat SDK for Android are:
- Android Lollipop 5.0 (API Level 21) or above
- Java 7 or higher
- Gradle 4.1.0 or higher
To integrate MirrorFly Chat SDK into your app, you will need a SDK License Key. The MirrorFly server will use this license key to authenticate the SDK in your application.
Step 1: Register here
Step 2: Login to your Account
Step 3: Get the License key from the
application Info’ section
Step 1: Create a new project or Open an existing project in Android Studio
Step 2: If using Gradle 6.8 or higher, add the following code to your settings.gradle file. If using Gradle 6.7 or lower, add the following code to your root build.gradle file. See this release note to learn more about updates to Gradle.
- Gradle 6.8 or higher
- Gradle 6.7 or lower
Step 3: Add the following dependencies in the app/build.gradle file.
Step 4: Add the below line in the gradle.properties file, to avoid imported library conflicts.
Step 5: Open the AndroidManifest.xml and add below permissions.
To start using the sdk, there is a need for some basic requirements before proceeding with the initialization process. In your
Application class, inside the onCreate() method use the below method from ChatManager to provide the necessary data.
|licenseKey||License key is required to proceed with registration|
Add the created MyApplication to AndroidManifest.xml.
The below method to register a user in sandbox Live mode based on
Unless you log out the session, make a note that should never call the registration method more than once in an application
Note: While registration, the below
registerUsermethod will accept the
LIST<METADATA>as an optional param and pass it across.
|USER_IDENTIFIER||A unique Id to Register the User. We accept only the AlphaNumeric String|
|FCM_TOKEN||A registration token that is generated by FCM SDK for the user's app instance to send message for free|
|USER_TYPE||type of the user|
|META_DATA||list of key - value pair of metadata object. |
|CALLBACK||FlyCallback is used as a callback, implemented and expressed as lambda expression for easy reading|
FORCE_REGISTER is false and it reached the maximum no of multi-sessions then registration will not succeed it will throw a 405 exception, Either
FORCE_REGISTER should be true or one of the existing session need to be logged out to continue registration.
Once Registration was successful, ChatSDK automatically attempts to connect to the Chat Server and ChatSDK also observe the changes in application lifecycle, and accordingly it will try to connect and disconnect the Chat Server.
ChatConnectionListener has been set, you will be able to receive the connection status in the callback method as mentioned below.
|CALLBACK||callback listener for chat connection|
Some of the most common terminologies used in Chat SDK with description
|userID/userBareID||Unique ID assigned for each user Ex: 12345678 (any alphanumeric). The below characters is not allowed in userId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@) userID should follow below specification: https://xmpp.org/extensions/xep-0106.html|
|userJid (or) JID||userID+@+domain of the chat server Ex. firstname.lastname@example.org|
|groupID/groupBareID||Unique ID assigned for each group Ex: group123456 (any alphanumeric). GroupJID = groupID +@mix.+domain of the chat server Ex: email@example.com`|
SDK will have built-in functions to prepare the JID, Group JID, and more.
Use the below method to send a text message to other user,
Note: To generate a unique user id, you must call the other user's
String userJID = FlyUtils.getJid(USERNAME)
|TO_JID||String||JID of the end user|
|TEXT||String||Indicates the text message that needs to be sent|
|CALLBACK||callback to observe the action status|
You need to initialise observer
MessageEventsListener to recieve any message and observe all the incoming messages sent to you.
Moreover, here the listeners would be called only when a new message is received from other user. To get more details please visit this callback listeners