Skip to content
codingtube

codingtube

Coding and Programming tutorials

  • javascript
  • React
  • ES6
  • React js
  • coding
  • ffmpeg
  • java
  • programming
  • information
  • coding
  • Privacy Policy
  • Twitter trends
  • Age Calculatore
  • Codingtube Community
  • YouTube Tags Generator
  • About
  • Toggle search form

Make Android chat app using Applozic SDK

Posted on December 5, 2021December 5, 2021 By christo No Comments on Make Android chat app using Applozic SDK

If you’re looking to make Android Real time chat app then here is full implementation of Applozic SDK

Introduction

Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emerging startups and established companies with the most scalable and powerful chat APIs, enabling application product teams to drive better user engagement, and reduce time-to-market.

Customers and developers from over 50+ countries use us and love us, from online marketplaces and eCommerce to on-demand services, to Education Tech, Health Tech, Gaming, Live-Streaming, and more.

Our feature-rich product includes robust client-side SDKs for iOS, Android, React Native, and Flutter. We also support popular server-side languages, a beautifully customizable UI kit, and flexible platform APIs.

Chat, video, and audio-calling have become the new norm in the post-COVID era, and we’re bridging the gap between businesses and customers by delivering those exact solutions.

Setting up Android Studio

  • Create a new project using File ➙ New Project on the top right of application
  • Rename the project as per your preference (we will name it as applozic-first-app)

Step 1: Adding in app build.gradle:

  • Make sure you open your app’s build.gradle (hint: Gradle Scripts ➙ build.grade(Module: <your-app-name>.app)) add the below line in dependencies{}.
implementation 'com.applozic.communication.uiwidget:mobicomkitui:5.102.0' 

Note: Versions from v5.99.0 and onwards will be hosted at Jfrog Artifactory.

Add the following repo to you project level build.gradle inside allProjects { repositories { … }}:

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

Older versions can still be consumed from Jcenter.

  • Add the below code in your gradle 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'
         }    

Step 2: Add Activities, Services and Receivers in androidmanifest.xml:

Note:

  • Add meta-data, Activities, Services and Receivers within application Tag <application> </application>
<!-- 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}" /> 
                     
  • Define Attachment Folder Name in your string.xml.
<string name="default_media_location_folder">YOUR_APP_NAME</string> 
  • Paste the following in your androidmanifest.xml:
<activity android:name="com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity"
           android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation"
           android:label="@string/app_name"
           android:parentActivityName="<APP_PARENT_ACTIVITY>"
           android:theme="@style/ApplozicTheme"
           android:launchMode="singleTask"
           tools:node="replace">
      <!-- Parent activity meta-data to support API level 7+ -->
<meta-data
           android:name="android.support.PARENT_ACTIVITY"
           android:value="<APP_PARENT_ACTIVITY>" />
 </activity>               
  • Replace APP_PARENT_ACTIVITY with your app’s parent activity (reference below).
<!-- you will be having .MainActivity-->
        <activity android:name="com.applozic.mobicomkit.uiwidgets.conversation.activity.ConversationActivity"
            android:configChanges="keyboardHidden|screenSize|smallestScreenSize|screenLayout|orientation"
            android:label="@string/app_name"
            android:parentActivityName=".MainActivity"
            android:theme="@style/ApplozicTheme"
            android:launchMode="singleTask"
            tools:node="replace">
            <!-- Parent activity meta-data to support API level 7+ -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>

Step 3: Register user account in your code:

  • For creating your first user we need to create an New user object which can be created using below code.
User user = new User();          
user.setUserId(userId); //userId it can be any unique user identifier
user.setDisplayName(displayName); //displayName is the name of the user which will be shown in chat messages
user.setEmail(email); //optional  
user.setAuthenticationTypeId(User.AuthenticationType.APPLOZIC.getValue());  //User.AuthenticationType.APPLOZIC.getValue() for password verification from Applozic server and User.AuthenticationType.CLIENT.getValue() for access Token verification from your server set access token as password
user.setPassword(""); //optional, leave it blank for testing purpose, read this if you want to add additional security by verifying password from your server https://www.applozic.com/docs/configuration.html#access-token-url
user.setImageLink("");//optional,pass your image link

 Applozic.connectUser(context, user, new AlLoginHandler() {
                @Override
                public void onSuccess(RegistrationResponse registrationResponse, Context context) {
                    // After successful registration with Applozic server the callback will come here 
                }

                @Override
                public void onFailure(RegistrationResponse registrationResponse, Exception exception) {
                    // If any failure in registration the callback  will come here 
             }
   });                                      

If it is a new user, new user account will get created else existing user will be logged in to the application. You can check if user is logged in to applozic or not by using Applozic.isConnected(context)

Step 4: Push Notification Setup 🔔

Note : Go to Applozic Dashboard, Edit Application -> Push Notification -> Android -> GCM/FCM Server Key.

  • Firebase Cloud Messaging (FCM) is already enabled in my app
    • Add the below code and pass the FCM registration token:
  1. UserLoginTask “onSuccess” (refer Step 3)
if(MobiComUserPreference.getInstance(context).isRegistered()) {
  Applozic.registerForPushNotification(context, registrationToken, new AlPushNotificationHandler() {
                @Override
                public void onSuccess(RegistrationResponse registrationResponse) {

                }

                @Override
                public void onFailure(RegistrationResponse registrationResponse, Exception exception) {

                }
    });
}
  1. In your FcmListenerService onNewToken(Token registrationToken) method
if (MobiComUserPreference.getInstance(this).isRegistered()) {
     new RegisterUserClientService(this).updatePushNotificationId(registrationToken);
}

For Receiving Notifications in FCM

  • Add the following in your FcmListenerService in onMessageReceived(RemoteMessage remoteMessage)
 if (MobiComPushReceiver.isMobiComPushNotification(remoteMessage.getData())) {
           MobiComPushReceiver.processMessageAsync(this, remoteMessage.getData());
           return;
   }

GCM is already enabled in my app

  • If you already have GCM enabled in your app, add the below code and pass the GCM registration token:
  1. In UserLoginTask “onSuccess” (refer Step 3)
if(MobiComUserPreference.getInstance(context).isRegistered()) {
  Applozic.registerForPushNotification(context, registrationToken, new AlPushNotificationHandler() {
                @Override
                public void onSuccess(RegistrationResponse registrationResponse) {

                }

                @Override
                public void onFailure(RegistrationResponse registrationResponse, Exception exception) {

                }
     });
}
  1. At the place where you are getting the GCM registration token in your app.
if (MobiComUserPreference.getInstance(this).isRegistered()) {
     new RegisterUserClientService(this).updatePushNotificationId(registrationToken);
}

For Receiving Notifications In GCM

  • Add the following in your GcmListenerService in onMessageReceived
if(MobiComPushReceiver.isMobiComPushNotification(data)) {            
        MobiComPushReceiver.processMessageAsync(this, data);               
        return;          
}                                          

Don’t have Android Push Notification code ?

  • To Enable Android Push Notification using Firebase Cloud Messaging (FCM)
    • visit the Firebase console
    • Create new project
    • Add the google service json to your app.
    • Configure the build.gradle files in your app.
    • Get server key from project settings.
    • Update in Applozic Dashboard under Push Notification -> Android -> GCM/FCM Server Key.
  • In case, if you don’t have the existing FCM related code, then copy the push notification related files from Applozic sample app to your project from the below github link
    • Github push notification code link
  • And add below code in your androidmanifest.xml file
<service android:name="<CLASS_PACKAGE>.FcmListenerService"
android:stopWithTask="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
</service>

Setup PushNotificationTask in UserLoginTask “onSuccess” (refer Step 3).

Applozic.registerForPushNotification(context, Applozic.getInstance(context).getDeviceRegistrationId(), new   AlPushNotificationHandler() {
                @Override
                public void onSuccess(RegistrationResponse registrationResponse) {

                }

                @Override
                public void onFailure(RegistrationResponse registrationResponse, Exception exception) {

                }
    });

Step 5: For starting the messaging activity

Intent intent = new Intent(this, ConversationActivity.class);            
startActivity(intent);                               
  • For starting individual conversation thread, set “userId” in intent:
Intent intent = new Intent(this, ConversationActivity.class);            
intent.putExtra(ConversationUIService.USER_ID, "receiveruserid123");             
intent.putExtra(ConversationUIService.DISPLAY_NAME, "Receiver display name"); //put it for displaying the title.  
intent.putExtra(ConversationUIService.TAKE_ORDER,true); //Skip chat list for showing on back press 
startActivity(intent);

Step 6: On logout, call the following:

Applozic.logoutUser(context, new AlLogoutHandler() {
                @Override
                public void onSuccess(Context context) {

                }

                @Override
                public void onFailure(Exception exception) {

                }
        });     
Full Project
android Tags:Android

Post navigation

Previous Post: basename in PHP
Next Post: Create Video Chat App using Node.js

Related Posts

Android to create Custom Toasts with TOASTY android
Android Activities android
How to create Text Spinner in Android android
Android gives error “Cannot fit requested classes in a single dex file” android
Face detection Android library using Camera api android
How to change the Apps Starting (Default) Activity in Android android

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Affiliate Marketing Principles
  • The Basics You Need to Know About Affiliate Marketing
  • Affiliate Marketing Options
  • All About Affiliate Marketing
  • Classification of Database Management Systems
  • Three-Tier and n-Tier Architectures
    for Web Applications
  • Two-Tier Client/Server Architectures for DBMSs
  • Basic Client/Server Architectures in DBMS
  • Centralized DBMSs Architecture in DBMS
  • Tools, Application Environments, and Communications Facilities in DBMS

Categories

  • Affiliate marketing (5)
  • Algorithm (43)
  • amp (3)
  • android (223)
  • Android App (8)
  • Android app review (4)
  • android tutorial (60)
  • Artificial intelligence (61)
  • AWS (3)
  • bitcoin (8)
  • blockchain (1)
  • c (5)
  • c language (105)
  • cloud computing (4)
  • coding (4)
  • coding app (4)
  • complex number (1)
  • Computer Graphics (66)
  • data compression (65)
  • data structure (188)
  • DBMS (44)
  • digital marketing (9)
  • distributed systems (11)
  • ffmpeg (26)
  • game (3)
  • html (6)
  • image processing (35)
  • Inequalities (1)
  • information (4)
  • java (212)
  • java network (1)
  • javascript (9)
  • kotlin (4)
  • leetcode (1)
  • math (21)
  • maven (1)
  • mysql (1)
  • Node.js (8)
  • operating system (109)
  • php (310)
  • Principle Of Mathematical Induction (1)
  • programming (6)
  • Python (4)
  • Python data structure (9)
  • React native (1)
  • React.js (22)
  • Redux (1)
  • seo (4)
  • set (12)
  • trigonometry (6)
  • vue.js (35)
  • XML (3)

sitemap

sitemap of videos

sitemap of webstories

sitemap of website

  • Affiliate marketing
  • Algorithm
  • amp
  • android
  • Android App
  • Android app review
  • android tutorial
  • Artificial intelligence
  • AWS
  • bitcoin
  • blockchain
  • c
  • c language
  • cloud computing
  • coding
  • coding app
  • complex number
  • Computer Graphics
  • data compression
  • data structure
  • DBMS
  • digital marketing
  • distributed systems
  • ffmpeg
  • game
  • html
  • image processing
  • Inequalities
  • information
  • java
  • java network
  • javascript
  • kotlin
  • leetcode
  • math
  • maven
  • mysql
  • Node.js
  • operating system
  • php
  • Principle Of Mathematical Induction
  • programming
  • Python
  • Python data structure
  • React native
  • React.js
  • Redux
  • seo
  • set
  • trigonometry
  • vue.js
  • XML
  • Blog
  • Data compression tutorial - codingpoint
  • How to change mbstring in php 5.6
  • How to diagnose out of memory killed PHP-FPM
  • Introduction to jQuery
  • Privacy
  • Affiliate marketing
  • Algorithm
  • amp
  • android
  • Android App
  • Android app review
  • android tutorial
  • Artificial intelligence
  • AWS
  • bitcoin
  • blockchain
  • c
  • c language
  • cloud computing
  • coding
  • coding app
  • complex number
  • Computer Graphics
  • data compression
  • data structure
  • DBMS
  • digital marketing
  • distributed systems
  • ffmpeg
  • game
  • html
  • image processing
  • Inequalities
  • information
  • java
  • java network
  • javascript
  • kotlin
  • leetcode
  • math
  • maven
  • mysql
  • Node.js
  • operating system
  • php
  • Principle Of Mathematical Induction
  • programming
  • Python
  • Python data structure
  • React native
  • React.js
  • Redux
  • seo
  • set
  • trigonometry
  • vue.js
  • XML
  • Blog
  • Data compression tutorial - codingpoint
  • How to change mbstring in php 5.6
  • How to diagnose out of memory killed PHP-FPM
  • Introduction to jQuery
  • Privacy

© codingtube.tech