Tutorials

Applozic Android SDK Tutorial 1 – Setup and Configuration

Integrate Applozic Android SDK to get started with your own chat application!
Google+ Pinterest LinkedIn Tumblr

In this tutorial you will be learning how to integrate the basic functionalities of Applozic Android SDK to get started with your own chat application.

Our goal is to complete the following steps in this tutorial:

  1. Create Applozic account and receive API key
  2. Set up Android Studio
  3. Integrate Applozic Chat SDK in your app
  4. Configure the basic dependencies for your app

Once these steps are complete, you can move on to Tutorial 2!

You can refer to the Applozic Android SDK documentation here.

Prerequisites

  1. Applozic account (Create your account here) for API/Application Key
  2. Android Studio (latest version)

Create Applozic account

Sign Up

Enter your personal dashboard after signing up for Applozic.

Sign up screen
Sign up screen

Get your App ID

Go to Settings > Configuration > Install.
Copy the App ID and use it whenever required.

This is your App ID. You can use this as a unique key for your application.
This is your App ID. You can use this as a unique key for your application.

Set up Android Studio

Creating New Project

Create a new project using File ➙ New Project on the top right of the application.

Create a new project
Create a new project

Select “Empty Activity” from the list under “Phone and Tablet”

Select Empty Activity > Next
Select Empty Activity > Next

Rename the project as per your preference. I will name mine as applozic-tutorial-app.
Make sure to set the minimum SDK as Android 6.0.

Add a unique name and set the minimum SDK supported
Add a unique name and set the minimum SDK supported

Wait for your background tasks to complete.

Background tasks
Background tasks

Now you are ready to integrate Applozic Chat SDK into your app!

Integrate Applozic Chat SDK in your app

Adding Applozic integrations to app gradle file

Open the file named as build.gradle (Module: app-name.app) inside Gradle Scripts.

Add the following dependency in your app’s build.gradle file under dependencies:

implementation 'com.applozic.communication.uiwidget:mobicomkitui:5.99.0' 

Now add the following packaging options inside the android target:

        packagingOptions {           
           exclude 'META-INF/DEPENDENCIES'      
           exclude 'META-INF/NOTICE'         
           exclude 'META-INF/LICENSE'      
           exclude 'META-INF/LICENSE.txt'    
           exclude 'META-INF/NOTICE.txt' 
           exclude 'META-INF/ECLIPSE_.SF'
           exclude 'META-INF/ECLIPSE_.RSA'
         }    

Your build.gradle(:app) file should look like this:

App build.gradle file
App build.gradle file

Adding Applozic integrations to project gradle file

Open the file named build.grade (Project: app-name).

Add the following repository:

maven {
    url 'https://applozic.jfrog.io/artifactory/applozic-android-sdk'
}

Your project’s build.gradle file should look like this:

Project build.gradle file
Project build.gradle file

With that, your Android Studio set up and integration with Applozic Android SDK is complete!

Configure the basic dependencies for your app

Configuring activity and meta-data

Open the AndroidManifest.xml file under manifests folder.

AndroidManifest.xml location
AndroidManifest.xml location

Replace the code inside the file with the following:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.applozic_tutorial_app">

    <application
        android:name=".MainActivity"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/ApplozicTheme"
        tools:ignore="Instantiatable">
        <activity
            android:name=".MainActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/MobiComAppBaseTheme">
        </activity>
        <activity
            android:name="com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity"
            android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:parentActivityName=".MainActivity"
            android:theme="@style/ApplozicTheme">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <!-- Applozic App ID -->
        <meta-data android:name="com.applozic.application.key"
            android:value="<YOUR_APPLOZIC_APP_ID" />
        <!-- Launcher white Icon -->
        <meta-data android:name="com.applozic.mobicomkit.notification.smallIcon"
            android:resource="YOUR_LAUNCHER_SMALL_ICON" />
        <!-- Notification color -->
        <meta-data android:name="com.applozic.mobicomkit.notification.color"
            android:resource="YOUR_NOTIFICATION_COLOR_RESOURCE" />
        <!--Replace with your geo api key from google developer console  -->
        <!-- For testing purpose use AIzaSyAYB1vPc4cpn_FJv68eS_ZGe1UasBNwxLI
        To disable the location sharing via map add this line ApplozicSetting.getInstance(context).disableLocationSharingViaMap(); in onSuccess of Applozic UserLoginTask -->
        <meta-data android:name="com.google.android.geo.API_KEY"
            android:value="YOUR_GEO_API_KEY" />
        <!-- NOTE: Do NOT change this, it should remain same i.e 'com.package.name' -->
        <meta-data android:name="com.package.name"
            android:value="${applicationId}" />
        <meta-data android:name="activity.open.on.notification"
            tools:node="replace" android:value="com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity" /> <!-- NOTE : Do NOT change this value -->
        <meta-data android:name="com.package.name"
            android:value="${applicationId}" /> <!-- NOTE: Do NOT change this, it should remain same i.e 'com.package.name' -->
    </application>
</manifest>

Now your AndroidManifest.xml file should look like this:

AndroidManifest.xml file
AndroidManifest.xml file
Make sure to replace the following with appropriate values:
YOUR_APPLOZIC_APP_ID
YOUR_LAUNCHER_SMALL_ICON
YOUR_NOTIFICATION_COLOR_RESOURCE
YOUR_GEO_API_KEY

Adding global string values

Now open strings.xml under app > res > values and add the following code:

<string name="default_media_location_folder">YOUR_APP_NAME</string> 

Your strings.xml file should look like this:

string.xml file
string.xml file

Configuring ProGuard rules

Add the following code into your proguard-rules.pro file:

#keep json classes                
 -keepclassmembernames class * extends com.applozic.mobicommons.json.JsonMarker {
     !static !transient <fields>;
 }

 -keepclassmembernames class * extends com.applozic.mobicommons.json.JsonParcelableMarker {
     !static !transient <fields>;
 }
-keep class com.applozic.** {
    !static !transient <fields>;
}
 #GSON Config          
-keepattributes Signature          
    
-keep class com.google.gson.examples.android.model.** { *; }            
-keep class org.eclipse.paho.client.mqttv3.logging.JSR47Logger { *; } 
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-dontwarn android.support.v4.**
-keep public class com.google.android.gms.* { public *; }
-dontwarn com.google.android.gms.**
-keep class com.google.gson.** { *; }

Your proguard-rules.pro file should look like this:

proguard-rules.pro file
proguard-rules.pro file

With that, we have now configured your application with all the basic and necessary dependencies!

End of Tutorial 1

In this tutorial, we have learnt how to:

  • Create Applozic account and receive API key
  • Set up Android Studio
  • Integrate Applozic Chat SDK in your app
  • Configure the basic dependencies for your app

You are now ready to move to Tutorial 2, Authentication and Authorization.

Author

Anurag is a Technical Writer and technology enthusiast who enjoys science fiction and PC gaming.