{"id":383839,"date":"2024-06-29T05:08:11","date_gmt":"2024-06-29T05:08:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=383839"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=383839","title":{"rendered":"<span>10 Easy Steps to Build an Android Chat App using Kotlin in 2022<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>This tutorial will guide you step by step in building an Android chat app in Kotlin with the help of third-party messaging SDKs. The reason I chose Kotlin for this tutorial is that &#8212; it is a lightweight programming language suggested by Google for building apps that work on Android devices.\u00a0<\/p>\n<p><strong><em>In the steps ahead, I\u2019ll show you how to develop an app in Android Studio, with messaging features that can integrate using SDKs. I use MirrorFly\u2019s chat SDKs throughout this tutorial. <\/em><\/strong><\/p>\n<h3>Step 1: Start a New Project in Android Studio  <\/h3>\n<p>As a long-term developer, I prefer to build my Android apps in the Android Studio IDE, due to its ease of use and generous updates. If you do not have it already on your device, you can download the latest version from their <u>Official Website<\/u>.\u00a0<\/p>\n<p>Launch the IDE after the installation completes. You will now be taken to the\u00a0 <strong>Welcome to Android Studio<\/strong> window.\u00a0<\/p>\n<p>This is where the project begins:<\/p>\n<p>Create a\u00a0 <strong>New Project<\/strong> by choosing a template from the many options available.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/75d\/426\/32a\/75d42632a0847218039b939148e14663.png\" width=\"1800\" height=\"1396\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/75d\/426\/32a\/75d42632a0847218039b939148e14663.png\"\/><figcaption><\/figcaption><\/figure>\n<p>For our project, I\u2019ll choose <strong>Empty Activity<\/strong> and click on <strong>Next.<\/strong>\u00a0<\/p>\n<p>Now we\u2019ll end up in the Configuration Window, where we need to fill in the details of our project.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7be\/cd1\/a58\/7becd1a58db565ebdece7836d0e0579d.png\" width=\"1800\" height=\"1399\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7be\/cd1\/a58\/7becd1a58db565ebdece7836d0e0579d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>First, I\u2019ll enter the app\u2019s name<\/p>\n<p>Next, I\u2019ll decide on the save location of this project\u00a0<\/p>\n<p>From the dropdown menu, I\u2019ll choose <strong>Kotlin, <\/strong>as we will be building the app using this language.<\/p>\n<p>And finally, choose <strong>Android 5.0 (Lollipop) <\/strong>as the minimum requirement to use this app and click on <strong>Finish.<\/strong><\/p>\n<h3>Step 2:\u00a0 Preparing the Project Library  <\/h3>\n<p>Once you land on the project page, we will be able to find many folders on the left pane. Here, we will have to navigate to the App\u2019s main <strong><em>folder > App > Libs<\/em><\/strong>. This is where we will be adding the dependency files of the chat SDKs.<\/p>\n<blockquote>\n<p>Note: If you\u2019ll need help with the extraction of the dependency files, check out this <a href=\"https:\/\/www.mirrorfly.com\/docs\/chat\/android\/quick-start\/\" rel=\"noopener noreferrer nofollow\"><u>guide<\/u><\/a>. <\/p>\n<\/blockquote>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9b3\/e97\/2bc\/9b3e972bc69496b86e549b1849e5d754.png\" width=\"479\" height=\"801\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9b3\/e97\/2bc\/9b3e972bc69496b86e549b1849e5d754.png\"\/><figcaption><\/figcaption><\/figure>\n<p>I can either drag and drop your downloaded files or upload them to the library folder under App. Let me go with the upload option in this scenario.\u00a0<\/p>\n<p>Next, we need to configure the compile, kotlin, and packaging options<\/p>\n<pre><code class=\"kotlin\"> plugins { ... id 'kotlin-android' id 'kotlin-kapt' }  android { compileOptions {     sourceCompatibility JavaVersion.VERSION_1_8     targetCompatibility JavaVersion.VERSION_1_8 }  kotlinOptions {     jvmTarget = '1.8' }  packagingOptions {     exclude 'META-INF\/AL2.0'     exclude 'META-INF\/DEPENDENCIES'     exclude 'META-INF\/LICENSE'     exclude 'META-INF\/LICENSE.txt'     exclude 'META-INF\/license.txt'     exclude 'META-INF\/NOTICE'     exclude 'META-INF\/NOTICE.txt'     exclude 'META-INF\/notice.txt'     exclude 'META-INF\/ASL2.0'     exclude 'META-INF\/LGPL2.1'     exclude(\"META-INF\/*.kotlin_module\") }  } <\/code><\/pre>\n<p>In the app\/build.gradle, add the following dependencies as shown below  <\/p>\n<pre><code class=\"kotlin\">dependencies {   ... \/\/ your app dependencies   implementation files('libs\/appbase.aar')  implementation files('libs\/flycommons.aar')  implementation files('libs\/flynetwork.aar')  implementation files('libs\/flydatabase.aar')  implementation files('libs\/videocompression.aar')  implementation files('libs\/xmpp.aar')   }<\/code><\/pre>\n<p>Call the following classes, need for the SDK integration  <\/p>\n<pre><code class=\"kotlin\"> dependencies {   ... \/\/ your app dependencies   configurations {      all {          exclude group: 'org.json', module: 'json'          exclude group: 'xpp3', module: 'xpp3'      }  }   \/\/For lifecycle listener  implementation 'android.arch.lifecycle:extensions:1.1.1'  annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'   \/\/For GreenDao  implementation 'de.greenrobot:greendao:2.1.0'   \/\/For gson parsing  implementation 'com.google.code.gson:gson:2.8.1'   \/\/for smack implementation  implementation 'org.igniterealtime.smack:smack-android:4.4.4'  implementation 'org.igniterealtime.smack:smack-tcp:4.4.4'  implementation 'org.igniterealtime.smack:smack-im:4.4.4'  implementation 'org.igniterealtime.smack:smack-extensions:4.4.4'  implementation 'org.igniterealtime.smack:smack-sasl-provided:4.4.4'   implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'  implementation 'androidx.multidex:multidex:2.0.1'  implementation 'com.google.android.gms:play-services-location:17.0.0'   \/\/Dagger Dependencies  api 'com.google.dagger:dagger:2.40.5'  kapt 'com.google.dagger:dagger-compiler:2.40.5'  api 'com.google.dagger:dagger-android:2.40.5'  api 'com.google.dagger:dagger-android-support:2.40.5'  kapt 'com.google.dagger:dagger-android-processor:2.40.5'   \/\/coroutines  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8'   \/\/apicalls  implementation 'com.squareup.retrofit2:retrofit:2.6.1'  implementation 'com.squareup.retrofit2:converter-gson:2.6.1'  implementation 'com.squareup.okhttp3:okhttp:4.2.0'  implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'   \/\/stetho interceptor  implementation 'com.facebook.stetho:stetho-okhttp3:1.3.1'   \/\/okhttp interceptor  implementation 'com.squareup.okhttp3:logging-interceptor:3.14.3'   \/\/shared preference encryption  implementation 'androidx.security:security-crypto:1.1.0-alpha03'   }<\/code><\/pre>\n<h3>Step 3: Configure the Manifest<\/h3>\n<p>This step defines every component of our app. When we configure the manifest, it will hold all the details of each element we are using in this project.\u00a0<\/p>\n<p>Since we deal with a good number of files, add the following code to the gradle.properties file so that we can restrain the execution of the app without any library conflict.<\/p>\n<pre><code>android.enableJetifier=true<\/code><\/pre>\n<p>Locate the manifest under the App folder and choose <strong>AndroidManifest.xml. <\/strong>Then, add the following code.   <\/p>\n<pre><code class=\"kotlin\">&lt;uses-permission android:name=\"android.permission.INTERNET\" \/> &lt;uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" \/> <\/code><\/pre>\n<h3>Step 4: Configure the Builder  <\/h3>\n<p>In this step, we will need to update the license key acquired from the third-party SDK provider account.<\/p>\n<p>Here, I have one from my MirrorFly account. Update it in the below code.\u00a0<\/p>\n<pre><code class=\"kotlin\">buildTypes {   debug { buildConfigField 'String', 'SDK_BASE_URL', '\"https:\/\/api-preprod-sandbox.mirrorfly.com\/api\/v1\/\"' buildConfigField 'String', 'LICENSE', '\"xxxxxxxxxxxxxxxxxxxxxxxxx\"' buildConfigField 'String', 'WEB_CHAT_LOGIN', '\"https:\/\/webchat-preprod-sandbox.mirrorfly.com\/\"' buildConfigField \"String\", \"SUPPORT_MAIL\", '\"contussupport@gmail.com\"'   } } <\/code><\/pre>\n<p>To make this work, we need to perform the gradle sync operation.\u00a0<\/p>\n<p>First, locate the gradle sync icon.<\/p>\n<p>This button disappeared from a new 3.1 version of AS Toolbar. Before it showed as:  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fb5\/577\/c65\/fb5577c651d6ce780055ea5396c00e5a.png\" width=\"700\" height=\"54\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fb5\/577\/c65\/fb5577c651d6ce780055ea5396c00e5a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>Now it&#8217;s missing:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b37\/8de\/3ad\/b378de3ad36bb1a03a1d965bb6b2048d.png\" width=\"898\" height=\"30\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b37\/8de\/3ad\/b378de3ad36bb1a03a1d965bb6b2048d.png\"\/><figcaption><\/figcaption><\/figure>\n<p>Otherwise, click on <strong>File <\/strong>and choose the option <strong>Sync Project with Gradle Files<\/strong><\/p>\n<p>Note: In order to see this change take effect, we need to restart the Android Studio IDE<\/p>\n<h3>Step 5: Start the Chat SDKs  <\/h3>\n<p>The next important step is that we need to initialize the chat SDKs<\/p>\n<p>To do this,\u00a0<\/p>\n<p>Call the onCreate() method in the\u00a0 Application Class as shown below:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/65f\/404\/35f\/65f40435f299f0ad5784f27f1a8d56ae.png\" width=\"1099\" height=\"543\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/65f\/404\/35f\/65f40435f299f0ad5784f27f1a8d56ae.png\"\/><figcaption><\/figcaption><\/figure>\n<p>And we\u2019ll need to continue adding the following code  <\/p>\n<pre><code class=\"kotlin\">\/\/For chat logging LogMessage.enableDebugLogging(BuildConfig.DEBUG)   ChatSDK.Builder() .setDomainBaseUrl(BuildConfig.SDK_BASE_URL) .setLicenseKey(BuildConfig.LICENSE) .setIsTrialLicenceKey(true) .build() <\/code><\/pre>\n<h3>Step 6: Registering a User  <\/h3>\n<p>We will use the following code to register a user in the sandbox live mode  <\/p>\n<pre><code class=\"kotlin\">  FlyCore.registerUser(USER_IDENTIFIER) { isSuccess, throwable, data ->     if(isSuccess) {         val responseObject = data.get(\"data\") as JSONObject         \/\/ Get Username and password from the object     } else {         \/\/ Register user failed print throwable to find the exception details.     }     }<\/code><\/pre>\n<h3>Step 7: Making a viable connection to the Chat Server  <\/h3>\n<p>Now that we\u2019ve configured the app, we need a central server to connect our apps across devices to make communication possible. Hence, we add the following code:  <\/p>\n<pre><code class=\"kotlin\">ChatManager.connect(object : ChatConnectionListener {       override fun onConnected() {            \/\/ Write your success logic here to navigate Profile Page or            \/\/ To Start your one-one chat with your friends       }        override fun onDisconnected() {           \/\/ Connection disconnected           \/\/No need implementations      }      override fun onConnectionNotAuthorized() {          \/\/ Connection Not authorized          \/\/No need implementations    }    })<\/code><\/pre>\n<h3>Step 8: Send a Text Message  <\/h3>\n<p>So, yes we are giving the app the capability to send text messages<\/p>\n<p>Let\u2019s add the below code<\/p>\n<pre><code class=\"kotlin\"> FlyMessenger.sendTextMessage(TO_JID, TEXT, listener = object : SendMessageListener {     override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {        \/\/ you will get the message sent success response          } }) <\/code><\/pre>\n<h3>Step 9: Receive a Text Message  <\/h3>\n<p>And next, we add the capability of receiving messages, using the following code.  <\/p>\n<pre><code class=\"kotlin\">  @Override public void onMessageReceived(@NonNull ChatMessage message) {     super.onMessageReceived(message);     \/\/ received message object } <\/code><\/pre>\n<h3>Step 10: Submit your app to Playstore  <\/h3>\n<p>Finally, we can debug and run the app in the sandbox live mode on the Android Studio IDE to spot any errors or bugs. Once our testing is done, it is time we submit our app to the Playstore.<\/p>\n<p>Note: This app is created only with the basic functionality of sending\/ receiving messages. However, if you would like to add more features to your app, explore them <a href=\"https:\/\/www.mirrorfly.com\/docs\/chat\/android\/quick-start\" rel=\"noopener noreferrer nofollow\"><u>here<\/u><\/a> and configure them as instructed\u00a0<\/p>\n<h2>Conclusion<\/h2>\n<p>Kudos, we\u2019ve made it! We\u2019ve built a chat app in less than 30 minutes with the help of Android Studio and <a href=\"https:\/\/www.mirrorfly.com\/in-app-chat-api.php\" rel=\"noopener noreferrer nofollow\">MirrorFly In-app Chat SDKs<\/a>. While this is a start of an app-building journey, we\u2019d like to introduce you to many more insights you\u2019d be interested in. Post in your needs and our team will work it out and bring you yet another useful article in a while. Until then, we bid you our bye!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/683898\/\"> https:\/\/habr.com\/ru\/articles\/683898\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>This tutorial will guide you step by step in building an Android chat app in Kotlin with the help of third-party messaging SDKs. The reason I chose Kotlin for this tutorial is that &#8212; it is a lightweight programming language suggested by Google for building apps that work on Android devices.\u00a0<\/p>\n<p><strong><em>In the steps ahead, I\u2019ll show you how to develop an app in Android Studio, with messaging features that can integrate using SDKs. I use MirrorFly\u2019s chat SDKs throughout this tutorial. <\/em><\/strong><\/p>\n<h3>Step 1: Start a New Project in Android Studio  <\/h3>\n<p>As a long-term developer, I prefer to build my Android apps in the Android Studio IDE, due to its ease of use and generous updates. If you do not have it already on your device, you can download the latest version from their <u>Official Website<\/u>.\u00a0<\/p>\n<p>Launch the IDE after the installation completes. You will now be taken to the\u00a0 <strong>Welcome to Android Studio<\/strong> window.\u00a0<\/p>\n<p>This is where the project begins:<\/p>\n<p>Create a\u00a0 <strong>New Project<\/strong> by choosing a template from the many options available.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>For our project, I\u2019ll choose <strong>Empty Activity<\/strong> and click on <strong>Next.<\/strong>\u00a0<\/p>\n<p>Now we\u2019ll end up in the Configuration Window, where we need to fill in the details of our project.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>First, I\u2019ll enter the app\u2019s name<\/p>\n<p>Next, I\u2019ll decide on the save location of this project\u00a0<\/p>\n<p>From the dropdown menu, I\u2019ll choose <strong>Kotlin, <\/strong>as we will be building the app using this language.<\/p>\n<p>And finally, choose <strong>Android 5.0 (Lollipop) <\/strong>as the minimum requirement to use this app and click on <strong>Finish.<\/strong><\/p>\n<h3>Step 2:\u00a0 Preparing the Project Library  <\/h3>\n<p>Once you land on the project page, we will be able to find many folders on the left pane. Here, we will have to navigate to the App\u2019s main <strong><em>folder > App > Libs<\/em><\/strong>. This is where we will be adding the dependency files of the chat SDKs.<\/p>\n<blockquote>\n<p>Note: If you\u2019ll need help with the extraction of the dependency files, check out this <a href=\"https:\/\/www.mirrorfly.com\/docs\/chat\/android\/quick-start\/\" rel=\"noopener noreferrer nofollow\"><u>guide<\/u><\/a>. <\/p>\n<\/blockquote>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>I can either drag and drop your downloaded files or upload them to the library folder under App. Let me go with the upload option in this scenario.\u00a0<\/p>\n<p>Next, we need to configure the compile, kotlin, and packaging options<\/p>\n<pre><code class=\"kotlin\"> plugins { ... id 'kotlin-android' id 'kotlin-kapt' }  android { compileOptions {     sourceCompatibility JavaVersion.VERSION_1_8     targetCompatibility JavaVersion.VERSION_1_8 }  kotlinOptions {     jvmTarget = '1.8' }  packagingOptions {     exclude 'META-INF\/AL2.0'     exclude 'META-INF\/DEPENDENCIES'     exclude 'META-INF\/LICENSE'     exclude 'META-INF\/LICENSE.txt'     exclude 'META-INF\/license.txt'     exclude 'META-INF\/NOTICE'     exclude 'META-INF\/NOTICE.txt'     exclude 'META-INF\/notice.txt'     exclude 'META-INF\/ASL2.0'     exclude 'META-INF\/LGPL2.1'     exclude(\"META-INF\/*.kotlin_module\") }  } <\/code><\/pre>\n<p>In the app\/build.gradle, add the following dependencies as shown below  <\/p>\n<pre><code class=\"kotlin\">dependencies {   ... \/\/ your app dependencies   implementation files('libs\/appbase.aar')  implementation files('libs\/flycommons.aar')  implementation files('libs\/flynetwork.aar')  implementation files('libs\/flydatabase.aar')  implementation files('libs\/videocompression.aar')  implementation files('libs\/xmpp.aar')   }<\/code><\/pre>\n<p>Call the following classes, need for the SDK integration  <\/p>\n<pre><code class=\"kotlin\"> dependencies {   ... \/\/ your app dependencies   configurations {      all {          exclude group: 'org.json', module: 'json'          exclude group: 'xpp3', module: 'xpp3'      }  }   \/\/For lifecycle listener  implementation 'android.arch.lifecycle:extensions:1.1.1'  annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'   \/\/For GreenDao  implementation 'de.greenrobot:greendao:2.1.0'   \/\/For gson parsing  implementation 'com.google.code.gson:gson:2.8.1'   \/\/for smack implementation  implementation 'org.igniterealtime.smack:smack-android:4.4.4'  implementation 'org.igniterealtime.smack:smack-tcp:4.4.4'  implementation 'org.igniterealtime.smack:smack-im:4.4.4'  implementation 'org.igniterealtime.smack:smack-extensions:4.4.4'  implementation 'org.igniterealtime.smack:smack-sasl-provided:4.4.4'   implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'  implementation 'androidx.multidex:multidex:2.0.1'  implementation 'com.google.android.gms:play-services-location:17.0.0'   \/\/Dagger Dependencies  api 'com.google.dagger:dagger:2.40.5'  kapt 'com.google.dagger:dagger-compiler:2.40.5'  api 'com.google.dagger:dagger-android:2.40.5'  api 'com.google.dagger:dagger-android-support:2.40.5'  kapt 'com.google.dagger:dagger-android-processor:2.40.5'   \/\/coroutines  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.8'  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.8'   \/\/apicalls  implementation 'com.squareup.retrofit2:retrofit:2.6.1'  implementation 'com.squareup.retrofit2:converter-gson:2.6.1'  implementation 'com.squareup.okhttp3:okhttp:4.2.0'  implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'   \/\/stetho interceptor  implementation 'com.facebook.stetho:stetho-okhttp3:1.3.1'   \/\/okhttp interceptor  implementation 'com.squareup.okhttp3:logging-interceptor:3.14.3'   \/\/shared preference encryption  implementation 'androidx.security:security-crypto:1.1.0-alpha03'   }<\/code><\/pre>\n<h3>Step 3: Configure the Manifest<\/h3>\n<p>This step defines every component of our app. When we configure the manifest, it will hold all the details of each element we are using in this project.\u00a0<\/p>\n<p>Since we deal with a good number of files, add the following code to the gradle.properties file so that we can restrain the execution of the app without any library conflict.<\/p>\n<pre><code>android.enableJetifier=true<\/code><\/pre>\n<p>Locate the manifest under the App folder and choose <strong>AndroidManifest.xml. <\/strong>Then, add the following code.   <\/p>\n<pre><code class=\"kotlin\">&lt;uses-permission android:name=\"android.permission.INTERNET\" \/> &lt;uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" \/> <\/code><\/pre>\n<h3>Step 4: Configure the Builder  <\/h3>\n<p>In this step, we will need to update the license key acquired from the third-party SDK provider account.<\/p>\n<p>Here, I have one from my MirrorFly account. Update it in the below code.\u00a0<\/p>\n<pre><code class=\"kotlin\">buildTypes {   debug { buildConfigField 'String', 'SDK_BASE_URL', '\"https:\/\/api-preprod-sandbox.mirrorfly.com\/api\/v1\/\"' buildConfigField 'String', 'LICENSE', '\"xxxxxxxxxxxxxxxxxxxxxxxxx\"' buildConfigField 'String', 'WEB_CHAT_LOGIN', '\"https:\/\/webchat-preprod-sandbox.mirrorfly.com\/\"' buildConfigField \"String\", \"SUPPORT_MAIL\", '\"contussupport@gmail.com\"'   } } <\/code><\/pre>\n<p>To make this work, we need to perform the gradle sync operation.\u00a0<\/p>\n<p>First, locate the gradle sync icon.<\/p>\n<p>This button disappeared from a new 3.1 version of AS Toolbar. Before it showed as:  <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Now it&#8217;s missing:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>Otherwise, click on <strong>File <\/strong>and choose the option <strong>Sync Project with Gradle Files<\/strong><\/p>\n<p>Note: In order to see this change take effect, we need to restart the Android Studio IDE<\/p>\n<h3>Step 5: Start the Chat SDKs  <\/h3>\n<p>The next important step is that we need to initialize the chat SDKs<\/p>\n<p>To do this,\u00a0<\/p>\n<p>Call the onCreate() method in the\u00a0 Application Class as shown below:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>And we\u2019ll need to continue adding the following code  <\/p>\n<pre><code class=\"kotlin\">\/\/For chat logging LogMessage.enableDebugLogging(BuildConfig.DEBUG)   ChatSDK.Builder() .setDomainBaseUrl(BuildConfig.SDK_BASE_URL) .setLicenseKey(BuildConfig.LICENSE) .setIsTrialLicenceKey(true) .build() <\/code><\/pre>\n<h3>Step 6: Registering a User  <\/h3>\n<p>We will use the following code to register a user in the sandbox live mode  <\/p>\n<pre><code class=\"kotlin\">  FlyCore.registerUser(USER_IDENTIFIER) { isSuccess, throwable, data ->     if(isSuccess) {         val responseObject = data.get(\"data\") as JSONObject         \/\/ Get Username and password from the object     } else {         \/\/ Register user failed print throwable to find the exception details.     }     }<\/code><\/pre>\n<h3>Step 7: Making a viable connection to the Chat Server  <\/h3>\n<p>Now that we\u2019ve configured the app, we need a central server to connect our apps across devices to make communication possible. Hence, we add the following code:  <\/p>\n<pre><code class=\"kotlin\">ChatManager.connect(object : ChatConnectionListener {       override fun onConnected() {            \/\/ Write your success logic here to navigate Profile Page or            \/\/ To Start your one-one chat with your friends       }        override fun onDisconnected() {           \/\/ Connection disconnected           \/\/No need implementations      }      override fun onConnectionNotAuthorized() {          \/\/ Connection Not authorized          \/\/No need implementations    }    })<\/code><\/pre>\n<h3>Step 8: Send a Text Message  <\/h3>\n<p>So, yes we are giving the app the capability to send text messages<\/p>\n<p>Let\u2019s add the below code<\/p>\n<pre><code class=\"kotlin\"> FlyMessenger.sendTextMessage(TO_JID, TEXT, listener = object : SendMessageListener {     override fun onResponse(isSuccess: Boolean, chatMessage: ChatMessage?) {        \/\/ you will get the message sent success response          } }) <\/code><\/pre>\n<h3>Step 9: Receive a Text Message  <\/h3>\n<p>And next, we add the capability of receiving messages, using the following code.  <\/p>\n<pre><code class=\"kotlin\">  @Override public void onMessageReceived(@NonNull ChatMessage message) {     super.onMessageReceived(message);     \/\/ received message object } <\/code><\/pre>\n<h3>Step 10: Submit your app to Playstore  <\/h3>\n<p>Finally, we can debug and run the app in the sandbox live mode on the Android Studio IDE to spot any errors or bugs. Once our testing is done, it is time we submit our app to the Playstore.<\/p>\n<p>Note: This app is created only with the basic functionality of sending\/ receiving messages. However, if you would like to add more features to your app, explore them <a href=\"https:\/\/www.mirrorfly.com\/docs\/chat\/android\/quick-start\" rel=\"noopener noreferrer nofollow\"><u>here<\/u><\/a> and configure them as instructed\u00a0<\/p>\n<h2>Conclusion<\/h2>\n<p>Kudos, we\u2019ve made it! We\u2019ve built a chat app in less than 30 minutes with the help of Android Studio and <a href=\"https:\/\/www.mirrorfly.com\/in-app-chat-api.php\" rel=\"noopener noreferrer nofollow\">MirrorFly In-app Chat SDKs<\/a>. While this is a start of an app-building journey, we\u2019d like to introduce you to many more insights you\u2019d be interested in. Post in your needs and our team will work it out and bring you yet another useful article in a while. Until then, we bid you our bye!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/683898\/\"> https:\/\/habr.com\/ru\/articles\/683898\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-383839","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=383839"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/383839\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=383839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=383839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=383839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}