Chat APIs and In-app Messaging SDKs for Developers

Applozic provides Chat APIs and In-app Messaging SDKs for Android, iOS and Web apps to power cross-device, multi-platform rich messaging.
Find comprehensive guides and platform-specific Chat API documentation to get started with In-app Messaging.

Get Started    

Android

Android Chat UI Customization and Settings

Our SDK's come with a pre-built UI that you can use to integrate with your application. Following is a list of things that you can customize in the pre-built UI.

In case you are looking for deeper customization, please feel free to use our UI source code mentioned below for reference to build your own UI.

Applozic customization json settings

Applozic provides easy settings to customize the message text color, message bubble background color, group options like create, add, remove to hide or show, show registered contacts, attachment background color, attachment options to hide or show

Follow the below steps for adding applozic-settings.json file:

1) Download applozic-settings.json file from here

2) Create an assets directory in app-->main and paste that applozic-settings.json file in the assets directory

Applozic settings Json Properties detail

Properties
Sample Value
Description

messageSearchOption

true/false

Message search option

onlineStatusMasterList

true/false

Online status Green Dot in Chat list

startNewButton

true/false

Start New Conversation Plus (+) Button

startNewGroup

true/false

Create group option

startNewFloatingButton

true/false

Start New Conversation Plus (+) FloatingActionButton

Properties
Sample Value
Description

receivedMessageTextColor

Color hex (#000000)

Received message text color

receivedMessageBackgroundColor

Color hex (#FFFFFFFF)

Received message chat bubble color

sentMessageBackgroundColor

Color hex (#FF03A9F4)

Sent message chat bubble color

sentMessageTextColor

Color hex (#FFFFFFFF)

Sent message text color

sendButtonBackgroundColor

Color hex (#FF03A9F4)

Send button background color

Properties
Sample Value
Description

receivedMessageBorderColor

Color hex (#FFFFFFFF )

Received message chat bubble border color

messageEditTextTextColor

Color hex (#000000)

Edit text text color

sentMessageBorderColor

Color hex (#FF03A9F4)

Sent Message chat bubble border color

attachmentIconsBackgroundColor

Color hex (#FF03A9F4)

Attachment icons background color

Properties
Sample Value
Description

maxAttachmentAllowed

int (Prefered 10)

Maximum attachment allowed to attach while sending Multiple attachments

Properties
Sample Value
Description

receivedMessageLinkTextColor

Color hex (#FFFFFFFF)

Received message hyper link text color

messageTimeTextColor

Color hex (#838b83)

Message time text color

conversationDateTextColor

Color hex (#333333)

Message date text color

conversationDayTextColor

Color hex (#333333)

Message day text color

sentMessageLinkTextColor

Color hex (#5fba7d)

Sent message hyper link text color

Properties
Sample Value
Description

receivedContactMessageTextColor

Color hex (#000000)

Received contact message text color

hideAttachmentButton

true/false

Show and hide media attachment button

sentContactMessageTextColor

Color hex (#FFFFFFFF)

Sent contact message text color

messageEditTextHintTextColor

Color hex (#bdbdbd)

Edit text hint text color

Properties
Sample Value
Description

locationShareViaMap

true/false

Location share activity

Properties
Sample Value
Description

channelCustomMessageBgColor

Color hex (#cccccc)

Group add, remove, left message background color

muteOption

true/false

Mute messages from group

channelCustomMessageBorderColor

Color hex (#cccccc)

Group add, remove, left message border color

channelCustomMessageTextColor

Color hex (#666666)

Group add, remove, left message text color

Properties
Sample Value
Description

groupInfoScreenVisible

true/false

Group information screen visibility

defaultGroupType

number

Sets the default group type if using the default ui for group creation.

hideGroupExitButton

true/false

Hide group exit option button in group

hideGroupAddMembersButton

true/false

Hide the add member option in group

hideGroupNameUpdateButton

true/false

Hide group name and group image change option in group

hideGroupRemoveMemberOption

true/false

Hide remove member option from group

Properties
Sample Value
Description

userProfileFragment

true/false

Show other user profile on click of App bar

Properties
Sample Value
Description

profileOption

true/false

Show and hide the profile option

broadcastOption

true/false

Broadcast option

Properties
Sample Value
Description

restrictedWordMessage

String

Restricted words are not allowed

Properties
Sample Value
Description

noConversationLabel

String

No conversation text label

noConversationLabelTextColor

Color hex (#000000)

No Conversation Label text color

Properties
Sample Value
Description

noSearchFoundForChatMessages

String

No search found text label

Properties
Sample Value
Description

showAllDeviceContacts

true/false

Show all registered and device contacts

inviteFriendsInContactActivity

true/false

Invite friends button in Contact list when no contacts are there

Properties
Sample Value
Description

registeredUserContactListCall

true/false

Registered users contact list call

totalRegisteredUserToFetch

int (Prefered 100)

Total Registered User to get from server for contact list

Properties
Sample Value
Description

refreshOption

true/false

Refresh chat for updates

blockOption

true/false

Block specific user

deleteOption

true/false

Delete chat of specific user

muteUserChatOption

true/false

Mute messages from specific user

Properties
Sample Value
Description

deleteOption

true/false

Delete messages from chat

forwardOption

true/false

Forward messages to others

replyOption

true/false

Reply to a specific message

recordButton

true/false

Record and share audio as a message

Properties
Sample Value
Description

createAnyContact

true/false

Launch a chat with any user in contact list

imageCompression

true/false

By default its disabled. You can enable the image compression using imageCompression properties

Chat thread tool bar settings

Properties
Sample Value
Description

hideGroupSubtitle

true/false

This will hide tool bar subtitle of chat thread

Customizing attachment options.

You can hide particular attachment options by setting value as false in attachmentOptions in applozic-settings.json file.

"attachmentOptions": {
      ":location": true,
      ":camera": true,
      ":file": true,
      ":audio": true,
      ":video": true,
      ":contact": true
    }

Example : to hide location option in attachment set :

":location": false

Settings programmatically

Either you can use apploizc-settings.json file and enable or disable options Or you can use programmatically settings to enable or disable settings

Add the below settings in onSuccess callback of applozic login link here

Disable deleted chat option completely

Remove delete option from chat screen and chat window

ApplozicSetting.getInstance(context).setDeleteConversationOption(true);    

Enabling badge circle dot in android O device and greater mobile OS

Add settings to enable to badge circle dot in android make sure uninstall the app and install

ApplozicClient.getInstance(context).enableShowUnreadCountBadge();

Show App icon in the notification

Add the below settings in Applozic login code of onSuccess callback of login

ApplozicClient.getInstance(context).showAppIconInNotification(true);

Notifications

You can enable/disable the notifications by calling the below methods:

ApplozicClient.getInstance(context).disableNotification();
ApplozicClient.getInstance(context).enableNotification();

Message Templates:

Applozic provides inbuilt , ready to use and easily customisable message templates. The structure as well as message list can be set from the applozic-settings.json file itself. The following is the structure for the same.

"messageTemplate": {
    "isEnabled": false,  //make this true to enable the templates
    "borderColor": "#ffffff",  //border color for the templates
    "backgroundColor": "#FF03A9F4", //background color for the templates
    "hideOnSend": false, //this will hide the templates when clicked for a single message
    "sendMessageOnClick": true,//will send a message with the value
    "cornerRadius": 20, //corner radius, increase this for more rounded 
    "textColor": "#ffffff",//text color within the template
    "messageList": {  //this is the message list with key value, the key will be displayed and the value will be sent as a message
      "Greetings": "Hey",
      "Help?": "How may I help you?",
      "Email-Id": "May I know your emailId",
      "Company": "May I know your company name?",
      "Platform?": "Is this related to Android, iOS, or web?",
      "Doc?": "Did you follow our doc?"
    },
    "textMessageList": {//this will be shown for the last message, if it is text message
      "showOnSenderSide": false, //if true, will be shown if last message is sent message
      "showOnReceiverSide": false, //if true, will be shown if last message is received message
      "sendMessageOnClick": false, //if true then message will be sent on click
      "messageList": { //put your messages here to be shown for the last message.
      }
    },
    "imageMessageList": {//this will be shown for the last message, if it is image message
      "showOnSenderSide": false,
      "sendMessageOnClick": false,
      "showOnReceiverSide": false,
      "messageList": {
      }
    },
    "videoMessageList": {//this will be shown for the last message, if it is video message
      "showOnSenderSide": false,
      "sendMessageOnClick": false,
      "showOnReceiverSide": false,
      "messageList": {
      }
    },
    "audioMessageList": {//this will be shown for the last message, if it is audio message
      "showOnSenderSide": false,
      "sendMessageOnClick": false,
      "showOnReceiverSide": false,
      "messageList": {
      }
    },
    "locationMessageList": {//this will be shown for the last message, if it is location message
      "showOnSenderSide": false,
      "sendMessageOnClick": false,
      "showOnReceiverSide": false,
      "messageList": {
      }
    },
    "contactMessageList": {//this will be shown for the last message, if it is contact message
      "showOnSenderSide": false,
      "sendMessageOnClick": false,
      "showOnReceiverSide": false,
      "messageList": {
      }
    }
  }

Note

If the messageList is not empty then it will be shown irrespective of textMessageList , imageMessageList etc. If you want to use the individual message list then make the messageList at the root empty otherwise the priority will be given to it over all the other lists.

Getting the message template click outside the SDK

If you want to receive the click event outside the SDK for your use, you can listen for the broadcast action com.applozic.mobicomkit.TemplateMessage and get the message by using the below code:

String message = intent.getStringExtra("templateMessage",null);

Make sure you register the broadcast receiver in your AndroidManifest.xml file or your Application class or else you won't receive the action if the chat was launched by notification.

Dynamic message templates

You can also set the template messages dynamically based on a particular user. You need to set the messages in ApplozicClient in applozic's login success.

Map<String, String> messageTemplates = new HashMap<>();
  messageTemplates.put("Greetings", "Hey there!");

  messageTemplates.put("Share my userId", "Hey there my userId is : " + registrationResponse.getUserId());

  if (!TextUtils.isEmpty(registrationResponse.getContactNumber())) {
       messageTemplates.put("Share my phone no.", "Hey there my contact number is : " + registrationResponse.getContactNumber());
            }

  if (!TextUtils.isEmpty(registrationResponse.getDisplayName())) {
       messageTemplates.put("Share my display name", "Hey there my Display name is : " + registrationResponse.getDisplayName());
            }
 ApplozicClient.getInstance(context).setMessageTemplates(messageTemplates);

If you set a message with same key as already defined in the applozic-settings.json file, then the dynamic one would replace the static one. For e.g. The Greetings key is already defined in the applozic-settings.json file with value Hey, but now that the same key is being set dynamically, the dynamic value would be used. In this case if you click on Greetings then Hey there! message would be sent instead of Hey.

Open your Activity on tap of toolbar in Chat Screen

To open a certain activity on tap of the toolbar in chat screen add the following in you AndroidManifest.xml file:

 <meta-data
    android:name="com.applozic.mobicomkit.uiwidgets.toolbar.tap.activity"
    android:value="PUT_ACTIVITY_CLASS_HERE" />

This activity will receive the userId of the selected chat in intent.

ActionBar Color/ToolBar Color for Conversation Screen

To customize the ActionBar/ToolBar color of theme, copy paste the following style in your theme's res file:

<style name="ApplozicTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <!--To change the toolbar color change the colorPrimary  -->
    <item name="colorPrimary">@color/applozic_theme_color_primary</item>

    <!-- To change the status bar  color change the color of colorPrimaryDark -->
    <item name="colorPrimaryDark">@color/applozic_theme_color_primary_dark</item>

    <!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets -->
    <item name="colorAccent">@color/applozic_theme_color_primary</item>

    <item name="windowActionModeOverlay">true</item>
  </style>

Change the name of the style from name="ApplozicTheme" to some new name and in your app AndroidManifest.xml file find for ApplozicTheme and replace with your new theme style.

UI source code

For complete control over UI, you can download our open source chat UI toolkit from this github link and change it as per your designs.
Import mobicomkitui library into your project and add the following in your app's build.gradle file's dependency:

  implementation project(':mobicomkitui')

Then go to mobicomkitui's build.gradle file and replace implementation project(':mobicomkit') by the below line

'com.applozic.communication.message:mobicomkit:<Use the current version code here>'

Warning!!!

Make sure you are not importing the mobicomkit and mobicommons modules from the source codes. You need to import just the mobicomkitui module and then import mobicomkit via gradle in mobicomkitui's gradle file as mentioned above.

MobiComKitUI contains the UI related source code, icons, layouts and other resources which you can customize based on your design needs.
For your custom contact list, replace MobiComKitPeopleActivity with your contact list activity.
Sample app with integration is available under app.

Fragment support

You can add the chat fragments to any activity. You need to clone the Applozic-Android-SDK and import the mobicomkitui module in your project. Below documentation links explain how to add the chat fragments to your activity:

Adding Chat fragment to your Activity

1) Add the below container layout in your activity layout. This will contain the chat fragment.

<RelativeLayout
       android:id="@+id/layout_child_activity"
       android:background="@color/conversation_list_all_background"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:layout_gravity="left|top" />

2) Open ConversationUIService.java file and add the below constructor:

MobiComQuickConversationFragment mobiComQuickConversationFragment;

public ConversationUIService(FragmentActivity fragmentActivity,MobiComQuickConversationFragment mobiComQuickConversationFragment) {
   this.fragmentActivity = fragmentActivity;
   this.mobiComQuickConversationFragment = mobiComQuickConversationFragment;
   this.baseContactService = new AppContactService(fragmentActivity);
       this.notificationManager  = (NotificationManager) fragmentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
   this.userPreference = MobiComUserPreference.getInstance(fragmentActivity);
  }
  • Find for getQuickConversationFragment() public method in ConversationUIService.java file replace that with below code :
public MobiComQuickConversationFragment getQuickConversationFragment() {
   return mobiComQuickConversationFragment;
}
  • Find for addMessage method in ConversationUIService.java file and replace it with below code:
public void addMessage(Message message) {
   if (message.isUpdateMessage()) {
       if (!BroadcastService.isQuick()) {
           return;
       }

       if (mobiComQuickConversationFragment != null) {
           if(message.isHidden()){
               mobiComQuickConversationFragment.refreshView();
           }else {
               mobiComQuickConversationFragment.addMessage(message);
           }
       }
   }
}

3) Open MobiComKitBroadcastReceiver.java and add the below constructor:

public MobiComKitBroadcastReceiver(FragmentActivity fragmentActivity,ConversationUIService conversationUIService) {
   this.conversationUIService = conversationUIService;
   this.baseContactService = new AppContactService(fragmentActivity);
}

4) In your Activity :

  • Add the below variables:
private static int retry;
ConversationUIService conversationUIService;
MobiComQuickConversationFragment mobiComQuickConversationFragment;
MobiComKitBroadcastReceiver mobiComKitBroadcastReceiver;
  • Add the below code in your onCreate() method:
mobiComQuickConversationFragment = new MobiComQuickConversationFragment();
conversationUIService = new ConversationUIService(this, mobiComQuickConversationFragment);
mobiComKitBroadcastReceiver = new MobiComKitBroadcastReceiver(this, conversationUIService);

  Intent lastSeenStatusIntent = new Intent(this, UserIntentService.class);
lastSeenStatusIntent.putExtra(UserIntentService.USER_LAST_SEEN_AT_STATUS, true);
startService(lastSeenStatusIntent);

addFragment(this, mobiComQuickConversationFragment, ConversationUIService.QUICK_CONVERSATION_FRAGMENT); //here we are adding fragment 
  • Add the below method to add the fragment in the container layout:
public static void addFragment(FragmentActivity fragmentActivity, Fragment fragmentToAdd, String fragmentTag) {
   FragmentManager supportFragmentManager = fragmentActivity.getSupportFragmentManager();

   FragmentTransaction fragmentTransaction = supportFragmentManager
           .beginTransaction();
   fragmentTransaction.replace(R.id.layout_child_activity, fragmentToAdd,
           fragmentTag);

   if (supportFragmentManager.getBackStackEntryCount() > 1) {
       supportFragmentManager.popBackStackImmediate();
   }
   fragmentTransaction.addToBackStack(fragmentTag);
   fragmentTransaction.commitAllowingStateLoss();
   supportFragmentManager.executePendingTransactions();
}
  • Implement these two interfaces in your Activity:
implements MessageCommunicator, MobiComKitActivityInterface
  • Replace the Overriden methods from the interfaces by the below methods:
@Override
public void onQuickConversationFragmentItemClick(View view, Contact contact, Channel channel,Integer conversationId,String searchString) {
 Intent intent = new Intent(this, ConversationActivity.class);
intent.putExtra(ConversationUIService.CONVERSATION_ID, conversationId);
intent.putExtra(ConversationUIService.SEARCH_STRING, searchString);
intent.putExtra(ConversationUIService.TAKE_ORDER, true);
if (contact != null) {
   intent.putExtra(ConversationUIService.USER_ID, contact.getUserId());
   intent.putExtra(ConversationUIService.DISPLAY_NAME, contact.getDisplayName());
   startActivity(intent);
} else if (channel != null) {
   intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
   intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
   startActivity(intent);

   }
}
@Override
public void startContactActivityForResult() {
   conversationUIService.startContactActivityForResult();
}

@Override
public void addFragment(ConversationFragment conversationFragment) {
   //NOT REQUIRED HERE..
}

@Override
public void updateLatestMessage(Message message, String number) {
   conversationUIService.updateLatestMessage(message, number);
}

@Override
public void removeConversation(Message message, String number) {
   conversationUIService.removeConversation(message, number);

}

@Override
public void showErrorMessageView(String errorMessage) {

}
@Override
public void retry() {
    retry++;
}
@Override
public int getRetryCount() {
    return retry;
}
  • In your Activity's onStop method add the below code:
@Override
protected void onStop() {
   super.onStop();
final String deviceKeyString = MobiComUserPreference.getInstance(this).getDeviceKeyString();
final String userKeyString = MobiComUserPreference.getInstance(this).getSuUserKeyString();
Intent intent = new Intent(this, ApplozicMqttIntentService.class);
intent.putExtra(ApplozicMqttIntentService.USER_KEY_STRING, userKeyString);
intent.putExtra(ApplozicMqttIntentService.DEVICE_KEY_STRING, deviceKeyString);
startService(intent);
}
  • In your Activity's onResume method add the below code:
@Override
protected void onResume() {
   super.onResume();
   LocalBroadcastManager.getInstance(this).registerReceiver(mobiComKitBroadcastReceiver, BroadcastService.getIntentFilter());
   Intent subscribeIntent = new Intent(this, ApplozicMqttIntentService.class);
   subscribeIntent.putExtra(ApplozicMqttIntentService.SUBSCRIBE, true);
   startService(subscribeIntent);

   if (!Utils.isInternetAvailable(this)) {
       String errorMessage = getResources().getString(R.string.internet_connection_not_available);
       showErrorMessageView(errorMessage);
   }
}
  • In your Activity's onPause method add the below code:
@Override
protected void onPause() {
   LocalBroadcastManager.getInstance(this).unregisterReceiver(mobiComKitBroadcastReceiver);
   super.onPause();
}

5) Open ConversationActivity.java file, find for the below lines and remove them:

else {
            setSearchListFragment(quickConversationFragment);
            addFragment(this, quickConversationFragment, ConversationUIService.QUICK_CONVERSATION_FRAGMENT);
        }

6) Open MobiComQuickConversationFragment.java file:

  • In onCreateView method find for the below lines and comment them out:
toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar); toolbar.setClickable(false);
  • In onCreateOptionsMenu method comment all the menu items out
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);

/*   if (!alCustomizationSettings.isStartNewButton()) {
       menu.removeItem(R.id.start_new);
   }else {
       menu.findItem(R.id.start_new).setVisible(true);
   }
   if (!alCustomizationSettings.isStartNewGroup()) {
       menu.removeItem(R.id.conversations);
   }else {
       menu.findItem(R.id.conversations).setVisible(true);
   }
   menu.findItem(R.id.refresh).setVisible(true);
   if(alCustomizationSettings.isProfileOption()){
       menu.findItem(R.id.applozicUserProfile).setVisible(true);
   }
   if(alCustomizationSettings.isMessageSearchOption()){
       menu.findItem(R.id.menu_search).setVisible(true);
   }
   if(alCustomizationSettings.isBroadcastOption()){
       menu.findItem(R.id.broadcast).setVisible(true);
   }*/
}

Then add this menu xml file in your activity and show/hide the menu items based on your requirements.

  • In onResume() method comment the below code:
/* toolbar.setTitle(ApplozicApplication.TITLE);
toolbar.setSubtitle("");*/

7) Wherever you are doing Applozic login using UserLoginTask add the below line of code in the onSuccess method:

ApplozicClient.getInstance(context).hideChatListOnNotification();

8) You need to handle the runtime permissions for storage in your activity for the contact images to load.

Adding chat fragment to your TabView Activity

1) Add the below lines to handle snack bar message in your tab activity xml file:

  <LinearLayout
        android:id="@+id/footerAd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="gone"
        android:layout_gravity="top">
    </LinearLayout>

2) Create a new instance of the MobiComQuickConversationFragment when setting up the view pager:

private void setupViewPager(ViewPager viewPager) {
//make global object of the MobiComQuickConversationFragment

    mobiComQuickConversationFragment = new MobiComQuickConversationFragment();//this is a fragment 
    //other stuff to setup the view pager with other tab fragments
}

3) Open the ConversationUIService.java class:

  • Add the below variable:
MobiComQuickConversationFragment mobiComQuickConversationFragment;
  • Add the below constructor:
public ConversationUIService(FragmentActivity fragmentActivity,MobiComQuickConversationFragment mobiComQuickConversationFragment) {     this.fragmentActivity = fragmentActivity;
    this.baseContactService = new AppContactService(fragmentActivity);
    this.userPreference = MobiComUserPreference.getInstance(fragmentActivity);
       this.notificationManager  = (NotificationManager) fragmentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
    this.mobiComQuickConversationFragment = mobiComQuickConversationFragment; 
}
  • Find for getQuickConversationFragment method and replace it with the below method:
public MobiComQuickConversationFragment getQuickConversationFragment() {
    return this.mobiComQuickConversationFragment;
}
  • Find for the addMessage and replace it with the below method:
public void addMessage(Message message) {
   if (message.isUpdateMessage()) {
       if (!BroadcastService.isQuick()) {
           return;
       }

       if (mobiComQuickConversationFragment != null) {
           if(message.isHidden()){
               mobiComQuickConversationFragment.refreshView();
           }else {
               mobiComQuickConversationFragment.addMessage(message);
           }
       }
   }
}

4) Open MobiComKitBroadcastReceiver.java and add the below constructor:

public MobiComKitBroadcastReceiver(FragmentActivity fragmentActivity, MobiComQuickConversationFragment mobiComQuickConversationFragment) {
   this.conversationUIService = new ConversationUIService(fragmentActivity,mobiComQuickConversationFragment);
   this.baseContactService = new AppContactService(fragmentActivity);
}

5) Open your Tab Activity:

  • Add the below variables:
private static int retry;
public LinearLayout layout;
public Snackbar snackbar;
MobiComKitBroadcastReceiver mobiComKitBroadcastReceiver;
ConversationUIService conversationUIService;
MobiComQuickConversationFragment mobiComQuickConversationFragment;
  • In your onCreate() method add the below code:
@Override
protected void onCreate(Bundle savedInstanceState) {
       layout = (LinearLayout) findViewById(R.id.footerAd);//this is snack bar layout

   ------
//The below code needs to be added after setting the fragments
    conversationUIService = new ConversationUIService(this, mobiComQuickConversationFragment);
    mobiComKitBroadcastReceiver = new MobiComKitBroadcastReceiver(this, mobiComQuickConversationFragment);
 
 ------
}
  • Implement these two interfaces in your tab activity:
implements MessageCommunicator, MobiComKitActivityInterface
  • Replace the Overriden methods from the interfaces by below methods:
@Override
public void showErrorMessageView(String message) {
    layout.setVisibility(View.VISIBLE);
    snackbar = Snackbar.make(layout, message, Snackbar.LENGTH_LONG);
    snackbar.setAction("OK", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            snackbar.dismiss();
        }
    });
    snackbar.setDuration(Snackbar.LENGTH_LONG);
    ViewGroup group = (ViewGroup) snackbar.getView();
    TextView textView = (TextView) group.findViewById(R.id.snackbar_action);
    textView.setTextColor(Color.YELLOW);
    group.setBackgroundColor(getResources().getColor(R.color.error_background_color));
    TextView txtView = (TextView) group.findViewById(R.id.snackbar_text);
    txtView.setMaxLines(5);
    snackbar.show();
}

@Override
public void retry() {
    retry++;
}

@Override
public int getRetryCount() {
    return retry;
}

public void dismissErrorMessage() {
    if (snackbar != null) {
        snackbar.dismiss();
    }
}

@Override
public void onQuickConversationFragmentItemClick(View view, Contact contact, Channel channel, Integer conversationId, String searchString) {
   Intent intent = new Intent(this, ConversationActivity.class);
   intent.putExtra(ConversationUIService.TAKE_ORDER, true);
   intent.putExtra(ConversationUIService.SEARCH_STRING, searchString);
   intent.putExtra(ConversationUIService.CONVERSATION_ID, conversationId);
   if (contact != null) {
       intent.putExtra(ConversationUIService.USER_ID, contact.getUserId());
       intent.putExtra(ConversationUIService.DISPLAY_NAME, contact.getDisplayName());
   } else if (channel != null) {
       intent.putExtra(ConversationUIService.GROUP_ID, channel.getKey());
       intent.putExtra(ConversationUIService.GROUP_NAME, channel.getName());
   }
   startActivity(intent); 
   }
   
@Override
public void startContactActivityForResult() {
    conversationUIService.startContactActivityForResult();
}

@Override
public void addFragment(ConversationFragment conversationFragment) {
}

@Override
public void updateLatestMessage(final Message message, final String formattedContactNumber) {
    conversationUIService.updateLatestMessage(message, formattedContactNumber);
}

@Override
public void removeConversation(Message message, String formattedContactNumber) {
    conversationUIService.removeConversation(message, formattedContactNumber);
}
  • In your Activity's onStop method add the below code:
@Override
protected void onStop() {
   super.onStop();
   final String deviceKeyString = MobiComUserPreference.getInstance(this).getDeviceKeyString();
   final String userKeyString = MobiComUserPreference.getInstance(this).getSuUserKeyString();
   Intent intent = new Intent(this, ApplozicMqttIntentService.class);
   intent.putExtra(ApplozicMqttIntentService.USER_KEY_STRING, userKeyString);
   intent.putExtra(ApplozicMqttIntentService.DEVICE_KEY_STRING, deviceKeyString);
   startService(intent);
}
  • In your Activity's onPause method add the below code:
@Override
protected void onPause() {
    LocalBroadcastManager.getInstance(this).unregisterReceiver(mobiComKitBroadcastReceiver);
    super.onPause();
}
  • In your Activity's onResume method add the below code:
@Override
protected void onResume() {
   super.onResume();
   LocalBroadcastManager.getInstance(this).registerReceiver(mobiComKitBroadcastReceiver, BroadcastService.getIntentFilter());
   Intent subscribeIntent = new Intent(this, ApplozicMqttIntentService.class);
   subscribeIntent.putExtra(ApplozicMqttIntentService.SUBSCRIBE, true);
   startService(subscribeIntent);

   if (!Utils.isInternetAvailable(getApplicationContext())) {
       String errorMessage = getResources().getString(R.string.internet_connection_not_available);
       showErrorMessageView(errorMessage);
   }
}

6) Open ConversationActivity.java, find for the below lines and remove/comment them:

 /*else {
            setSearchListFragment(quickConversationFragment);
            addFragment(this, quickConversationFragment, ConversationUIService.QUICK_CONVERSATION_FRAGMENT);
        }
*/

7) Open MobiComQuickConversationFragment.java:

  • In onCreateView comment the below lines of code:
/*  toolbar = (Toolbar) getActivity().findViewById(R.id.my_toolbar);
 toolbar.setClickable(false);*/
  • In onCreateOptionMenu comment all the menu items out:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   super.onCreateOptionsMenu(menu, inflater);

/*   if (!alCustomizationSettings.isStartNewButton()) {
       menu.removeItem(R.id.start_new);
   }else {
       menu.findItem(R.id.start_new).setVisible(true);
   }
   if (!alCustomizationSettings.isStartNewGroup()) {
       menu.removeItem(R.id.conversations);
   }else {
       menu.findItem(R.id.conversations).setVisible(true);
   }
   menu.findItem(R.id.refresh).setVisible(true);
   if(alCustomizationSettings.isProfileOption()){
       menu.findItem(R.id.applozicUserProfile).setVisible(true);
   }
   if(alCustomizationSettings.isMessageSearchOption()){
       menu.findItem(R.id.menu_search).setVisible(true);
   }
   if(alCustomizationSettings.isBroadcastOption()){
       menu.findItem(R.id.broadcast).setVisible(true);
   }*/
}

Then add this menu xml file in your activity and show/hide the menu items based on your requirements.

  • In onResume() method comment the below code:
/* toolbar.setTitle(ApplozicApplication.TITLE);
toolbar.setSubtitle("");*/

8) Wherever you are doing Applozic login using UserLoginTask add the below line of code in the onSuccess method:

ApplozicClient.getInstance(context).hideChatListOnNotification();

9) You need to handle the runtime permissions for storage in your activity for the contact images to load.

10) Add the tab Listener to load the fragment on tab change, call the onResume method of that fragment which you have added in the ViewPager by item position

For eg. For adding the Listener and loading the fragment on tab change/switch:

tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
   @Override
   public void onTabSelected(TabLayout.Tab tab) {
       viewPager.setCurrentItem(tab.getPosition(),true);
       switch (tab.getPosition()) {
           case 0:
            //Explicitly load the MobiComQuickConversationFragment by item position
                viewPagerAdapter.getItem(0).onResume();
                    break;

       }
   }

   @Override
   public void onTabUnselected(TabLayout.Tab tab) {


   }

   @Override
   public void onTabReselected(TabLayout.Tab tab) {

   }
});

Audio/Video call with Applozic chat

We do not provide audio/video call from Applozic SDK side below setting can help you in implementing the third party integration.

You can enable the call button in one to one chat pre-built UI and launch your own screen to start an audio/video call.

Add this in onSuccess of your Applozic login:

Step: 1
Below setting will enable the call button(Audio/Video) in the UI.

ApplozicClient.getInstance(context).setIPCallEnabled(true);
               
try {
   Map<ApplozicSetting.RequestCode, String> activityCallbacks = new HashMap<>();
   activityCallbacks.put(ApplozicSetting.RequestCode.AUDIO_CALL, Class.forName("com.something.YourAudioCallActivity").getName());   //set fully classified name for your AudioCallActivity
  
   activityCallbacks.put(ApplozicSetting.RequestCode.VIDEO_CALL, Class.forName("com.something.YourVideoCallActivity").getName());   //set fully classified name for your AudioCallActivity
    
   ApplozicSetting.getInstance(context).setActivityCallbacks(activityCallbacks);
     
} catch(ClassNotFoundException e) {
   e.printStackTrace();
}

Step 2:

Below code informs to Applozic that user is trying to access the calling feature and you will have to add call the actual code to start the audio/video calling.

On click of audio call button in the one to one chat thread your AudioCallActivity will open, and on click of the video call button from one to one chat thread, your VideoCallActivity will open. The intent received in both these activities will have the userId of the user.
Get the userId as below:

String userIdOfCallReceiver = getIntent.getStringExtra("CONTACT_ID");

You can then start the audio/video call with the user.


What's Next

Localization