Chat APIs and In-app Messaging SDKs for Developers, by Developers

Applozic powers multi-platform Chat APIs and in-app Messaging SDKs for Android, iOS and the Web that will enable you to build advanced in-app chat solutions your users will love.

Integrate chat in your application with completely customizable UI kits, powerful messaging APIs and SDKs, developed with exceptional security measures in mind.

Documentation    API Explorer

Android

Android contacts setup

The below methods are for creating contacts to be stored locally on the user's device.
You can create the contact list in two easy steps by using AppContactService.java api. Sample method buildContactData() for adding contacts is present in sample app's MainActivity.java.
##Creating contact
You can create a contact as below:

Contact contact = new Contact();            
contact.setUserId(<userId>);//Unique ID to identify contact
contact.setFullName(<full name of contact>);                 
contact.setEmailId(<EmailId>);               
contact.setImageURL(<image http URL OR android resource drawable>);              
//in case of drawable use R.drawable.<resource_name>
val contact = Contact()
 contact.userId = "<USER_ID>"//Unique ID to identify contact
 contact.fullName = "<DISPLAY_NAME>"
 contact.emailId = "<EMAIL_ID>"
 contact.imageURL = "<IMAGE_URL>"

Example:

Contact contact = new Contact();                 
contact.setUserId("adarshk");           
contact.setFullName("Adarsh");               
contact.setImageURL("R.drawable.applozic_ic_contact_picture_holo_light");
contact.setEmailId("[email protected]");
val contact = Contact()
contact.userId = "adarshk"
contact.fullName = "Adarsh"
contact.imageURL = "R.drawable.applozic_ic_contact_picture_holo_light"
contact.emailId = "[email protected]"

Saving a contact

Save the contact using AppContactService.java's add() method.

Context context = getApplicationContext();           
AppContactService appContactService = new AppContactService(context);    
appContactService.add(contact);
val context = applicationContext
val appContactService = AppContactService(context)
appContactService.add(contact)

AppContactService at a Glance

AppContactService.java provides methods you need to add, delete and update contacts.

  • Add single contact
add(Contact contact)
  • Add multiple contacts
addAll(List<Contact> contactList)
  • Delete contact
deleteContact(Contact contact)
  • Delete contact by Id
deleteContactById(String contactId)
  • Read contact by Id
getContactById(String contactId )
  • Update contact
updateContact(Contact contact)
  • Update or Insert contact
upsert(Contact contact)

Show all Contacts

To show all contacts use below setting in assets/applozic-settings.json file

"registeredUserContactListCall": false, // set to true for displaying all registered users in the contact list

Categorize Contacts

Categorizing contacts is one of the ways we support where groups can be created based on common interests or activities. Follow the steps mentioned below to group contacts together and show the users contacts from a particular group.

Creating a contacts group

It will create a group and add members in that contacts group.

First create a task to create new contacts group and add a member into that contacts group.

ApplozicAddMemberToContactGroupTask.GroupMemberListener listener = new ApplozicAddMemberToContactGroupTask.GroupMemberListener(){
            @Override
            public void onSuccess(boolean response, Context context){

            }

            @Override
            public void onFailure(boolean response, Exception e, Context context){

            }
        };

        List<String> groupMemberList = new ArrayList<>();
        groupMemberList.add("userIdOne");// replace with userId
        groupMemberList.add("userIdTwo");// replace with userId

        ApplozicAddMemberToContactGroupTask applozicAddMemberToContactGroupTask = new ApplozicAddMemberToContactGroupTask(context, GroupNameORClientGroupId, null, groupMemberList, listener);
val listener: ApplozicAddMemberToContactGroupTask.GroupMemberListener = object : ApplozicAddMemberToContactGroupTask.GroupMemberListener {
            override fun onSuccess(response: Boolean, context: Context?) {
                // Success
            }

            override fun onFailure(response: Boolean, e: java.lang.Exception?, context: Context?) {
                // Failure
            }
        }

        val groupMemberList: MutableList<String> = ArrayList()
        groupMemberList.add("userIdOne") // replace with userId
        groupMemberList.add("userIdTwo") // replace with userId
val applozicAddMemberToContactGroupTask = ApplozicAddMemberToContactGroupTask(context, GroupNameORClientGroupId, null, groupMemberList, listener)

Now execute this task using:

AlTask.execute(applozicAddMemberToContactGroupTask);
AlTask.execute(applozicAddMemberToContactGroupTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use applozicAddMemberToContactGroupTask.execute(); instead.

Adding member into a contacts group

Pass the GroupName or clientGroupId which is unique and has been created before.

To do so, first create a ApplozicAddMemberToContactGroupTask:

ApplozicAddMemberToContactGroupTask.GroupMemberListener listener = new ApplozicAddMemberToContactGroupTask.GroupMemberListener(){
            @Override
            public void onSuccess(boolean response, Context context){

            }

            @Override
            public void onFailure(boolean response, Exception e, Context context){

            }
        };

        List<String> groupMemberList = new ArrayList<>();
        groupMemberList.add("userIdOne");// replace with userId whom you want to add

        ApplozicAddMemberToContactGroupTask applozicAddMemberToContactGroupTask = new ApplozicAddMemberToContactGroupTask(context, GroupNameORClientGroupId, "9", groupMemberList, listener);
val listener: ApplozicAddMemberToContactGroupTask.GroupMemberListener = object : ApplozicAddMemberToContactGroupTask.GroupMemberListener {
            override fun onSuccess(response: Boolean, context: Context?) {}
            override fun onFailure(response: Boolean, e: java.lang.Exception?, context: Context?) {}
        }

        val groupMemberList: MutableList<String> = ArrayList()
        groupMemberList.add("userIdOne") // replace with userId whom you want to add

val applozicAddMemberToContactGroupTask = ApplozicAddMemberToContactGroupTask(context, GroupNameORClientGroupId, "9", groupMemberList, listener)

Then execute the task using:

AlTask.execute(applozicAddMemberToContactGroupTask);
AlTask.execute(applozicAddMemberToContactGroupTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use applozicAddMemberToContactGroupTask.execute(); instead.

Enable contact groups


You can use the below settings for the contacts categorizing before launching the chat list or individual chat thread Example: starting the ConversationActivity.java you can set the contacts groupId and on successfully

MobiComUserPreference.getInstance(context).setContactsGroupId("GroupNameORClientGroupId");
MobiComUserPreference.getInstance(context).contactsGroupId = "GroupNameORClientGroupId"

Remove a member from the group:

First create a task which will be used for removing a member from that contacts group:

RemoveMemberFromContactGroupTask.RemoveGroupMemberListener listener = new RemoveMemberFromContactGroupTask.RemoveGroupMemberListener(){
        @Override
        void onSuccess(String response, Context context){
        
        }

        @Override
        void onFailure(String response, Exception e, Context context){
        
        }
}


RemoveMemberFromContactGroupTask removeMemberFromContactGroupTask = new RemoveMemberFromContactGroupTask(context, GroupNameORClientGroupId, "", userId, listener);
val listener: RemoveMemberFromContactGroupTask.RemoveGroupMemberListener = object : RemoveMemberFromContactGroupTask.RemoveGroupMemberListener {
            override fun onSuccess(response: String?, context: Context?) {
            }

            override fun onFailure(response: String?, e: java.lang.Exception?, context: Context?) {
            }

        }
 val removeMemberFromContactGroupTask = RemoveMemberFromContactGroupTask(context, GroupNameORClientGroupId, "", userId, listener)

Then execute this task using:

AlTask.execute(removeMemberFromContactGroupTask);
AlTask.execute(removeMemberFromContactGroupTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use removeMemberFromContactGroupTask.execute(); instead.

  • Get the user Id of all the members in the group:

Create a ApplozicGetMemberFromContactGroupTask. You can use this task if you are building your own contacts listing screen and you want to get the users which are in that contacts group.

ApplozicGetMemberFromContactGroupTask.GroupMemberListener listener = new ApplozicGetMemberFromContactGroupTask.GroupMemberListener(){
      @Override
      void onSuccess(String[] userIdArray, Context context){
          //here is the userIds
      }

      @Override
       void onFailure(String userIdArray, Context context){
       
       }
}

ApplozicGetMemberFromContactGroupTask applozicGetMemberFromContactGroupTask = new ApplozicGetMemberFromContactGroupTask(context, contactGroupId, "", listener);

Then execute the task using:

AlTask.execute(applozicGetMemberFromContactGroupTask);
AlTask.execute(applozicGetMemberFromContactGroupTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use applozicGetMemberFromContactGroupTask.execute(); instead.

Registered users detail

The below async is used for fetching the list of registered users in applozic application

  1. Load the latest registered users
    2.Load the next set of registered users

  2. Use the below RegisteredUsersAsyncTask to fetch the registered users list:

RegisteredUsersAsyncTask.TaskListener usersAsyncTaskTaskListener = new RegisteredUsersAsyncTask.TaskListener() {
  @Override
  public void onSuccess(RegisteredUsersApiResponse registeredUsersApiResponse, String[] userIdArray) {

   Set < UserDetail > userDetailList = registeredUsersApiResponse.getUsers(); // THis will have list of user details

   if (userDetailList != null && userDetailList.size() > 0) {
    for (UserDetail userDetail: userDetailList) {

     Log.i("UserDetail", "object detail: " + userDetail);
     // You can get the user id : userDetail.getUserId();
     // You can get the display name : userDetail.getDisplayName();
     // You can get the profile image link :  userDetail.getImageLink();
     // You can get the online status of the user :  userDetail.isConnected() if this is true its connected
     // You can check out UserDetail for more details
    }
   }
  }

  @Override
  public void onFailure(RegisteredUsersApiResponse registeredUsersApiResponse, String[] userIdArray, Exception exception) {

  }

  @Override
  public void onCompletion() {

  }
 };
 RegisteredUsersAsyncTask usersAsyncTask = new RegisteredUsersAsyncTask(this, usersAsyncTaskTaskListener, ApplozicSetting.getInstance(this).getTotalRegisteredUsers(), 0L, null, null, true);
val usersAsyncTaskTaskListener: RegisteredUsersAsyncTask.TaskListener = object : RegisteredUsersAsyncTask.TaskListener {
            override fun onSuccess(registeredUsersApiResponse: RegisteredUsersApiResponse?, userIdArray: Array<String>?) {
                if (registeredUsersApiResponse != null) {
                    val userDetailList = registeredUsersApiResponse.users // THis will have list of user details
                    if (userDetailList != null && userDetailList.size > 0) {
                        for (userDetail in userDetailList) {
                            Log.i("UserDetail", "object detail: $userDetail")
                            // You can get the user id : userDetail.getUserId();
                            // You can get the display name : userDetail.getDisplayName();
                            // You can get the profile image link :  userDetail.getImageLink();
                            // You can get the online status of the user :  userDetail.isConnected() if this is true its connected
                            // You can check out UserDetail for more details
                        }
                    }
                }
            }

            override fun onFailure(registeredUsersApiResponse: RegisteredUsersApiResponse?, userIdArray: Array<String>?, exception: java.lang.Exception?) {}
            override fun onCompletion() {}
        }
        val usersAsyncTask = RegisteredUsersAsyncTask(this, usersAsyncTaskTaskListener, ApplozicSetting.getInstance(this).totalRegisteredUsers, 0L, null, null, true)

Then execute the task using:

AlTask.execute(usersAsyncTask);
AlTask.execute(usersAsyncTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use usersAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); instead.

  1. Pagination to load the next set of registered use the same above RegisteredUsersAsyncTask code and pass the

MobiComUserPreference.getInstance(this).getRegisteredUsersLastFetchTime()
in place of 0L

Build your UI from scratch - User

This will guide you one user API methods

User block or unblock in one to one chat

Create a task for blocking the user or unblocking user in chat:

UserBlockTask.TaskListener  taskListener = new UserBlockTask.TaskListener() {
            @Override
            public void onSuccess(ApiResponse apiResponse) {

             Log.i(" Block Status","User is blocked or unblocked"+apiResponse.isSuccess());
            }

            @Override
            public void onFailure(ApiResponse apiResponse, Exception exception) {

            }

            @Override
            public void onCompletion() {

            }
        };

        UserBlockTask userBlockTask = new UserBlockTask(getContext(), taskListener, "<RECEIVER-USER-ID>", blockOrUnBlock);
val taskListener: UserBlockTask.TaskListener = object : UserBlockTask.TaskListener {
            override fun onSuccess(apiResponse: ApiResponse<*>?) {
                if (apiResponse != null) {
                    Log.i(" Block Status", "User is blocked or unblocked" + apiResponse.isSuccess)
                }
            }

            override fun onFailure(apiResponse: ApiResponse<*>?, exception: java.lang.Exception?) {}
            override fun onCompletion() {}
        }

 val userBlockTask = UserBlockTask(context, taskListener, "<RECEIVER-USER-ID>", blockOrUnBlock)

Argument

Type

Description

userId

String

Pass the receiver userId for block or un block user

blockOrUnBlock

boolean

Pass true in case of blocking user. Pass false in case of un blocking user

Then execute the task using:

AlTask.execute(userBlockTask);
AlTask.execute(userBlockTask)

🚧

Note for older versions:

For SDK versions lesser than v5.95 use userBlockTask.execute((Void) null); instead.

Updated 8 months ago


What's Next

Groups

Android


Android contacts setup

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.