Displaying UI

Once the authentication is done, you can now launch the chat functionality directly in your app using the UI provided to you by the CometChat SDK.

The SDK provides you with two options to launch the UI. They are:

Launch CometChat

This option allows you to launch the entire chat functionality into your Android application. Once launched all the functionalities are handled by the SDK and you have a ready-to-go chat feature implemented in your android application.


LaunchCometChat(Activity activity, boolean isFullscreen, ILaunchCallbacks callbacks)

e.g


cometChat.LaunchCometChat(this, true, new LaunchCallbacks(successObj => success(successObj), fail => failObj(fail), onChatroomInfo => ChatroomInfo(onChatroomInfo), onError => Error(onError), onLogout => Logout(onLogout), onMessageReceive => MessageReceive(onMessageReceive), onUserInfo => UserInfo(onUserInfo)) ); public void failObj(JSONObject p0) { //block of code } public void success(JSONObject p0) { //block of code } public void fail(JSONObject p0) { //block of code } public void ChatroomInfo(JSONObject p0) { //block of code } public void Error(JSONObject p0) { //block of code } public void Logout(JSONObject p0) { //block of code } public void MessageReceive(JSONObject p0) { //block of code } public void UserInfo(JSONObject p0) { //block of code }

Where LaunchCallbacks is as follows :

public class LaunchCallbacks : Java.Lang.Object, ILaunchCallbacks
{
    Action<Org.Json.JSONObject> _onSuccess;
    Action<Org.Json.JSONObject> _onFail;
    Action<Org.Json.JSONObject> _onGroupInfo;
    Action<Org.Json.JSONObject> _onError;
    Action<Org.Json.JSONObject> _onLogout;
    Action<Org.Json.JSONObject> _onMessageReceive;
    Action<Org.Json.JSONObject> _onUserInfo;

    public LaunchCallbacks(Action<Org.Json.JSONObject> onSuccess, Action<Org.Json.JSONObject> onFail, Action<Org.Json.JSONObject> onGroupInfo,                       
    Action<Org.Json.JSONObject> onError, Action<Org.Json.JSONObject> onLogout, Action<Org.Json.JSONObject> onMessageReceive, 
    Action<Org.Json.JSONObject> onUserInfo)
    {
        this._onFail = onFail;
        this._onSuccess = onSuccess;
        this._onGroupInfo = onGroupInfo;
        this._onError = onError;
        this._onLogout = onLogout;
        this._onMessageReceive = onMessageReceive;
        this._onUserInfo = onUserInfo;
    }



    public void FailCallback(JSONObject p0)
    {
        this._onFail?.Invoke(p0);
    }

    public void SuccessCallback(JSONObject p0)
    {
        this._onSuccess?.Invoke(p0);
    }

    public void onGroupInfo(JSONObject p0)
    {
        this._onGroupInfo?.Invoke(p0);
    }

    public void Error(JSONObject p0)
    {
        this._onError?.Invoke(p0);
    }

    public void OnMessageReceive(JSONObject p0)
    {
        this._onMessageReceive?.Invoke(p0);
    }

    public void UserInfoCallback(JSONObject p0)
    {
        this._onUserInfo?.Invoke(p0);
    }

    public void OnLogout()
    {

    }
}

Parameters
Activity – Instance of the activity.
isFullScreen – A boolean value which when set to true launches the UI in full screen. Setting this value to false will launch the UI in a popup.
callbacks – This callback provides you with a set of methods to provide you information regarding the data fetched from the server.

The methods in the callback provide you with the following information

Method Details
successCallback This method is triggered once the request to launch CometChat is executed successfully
failCallback This is triggered when there is some issue when launching CometChat.
userInfoCallback This method is called when the user data is fetched from the server.
onGroupInfo This method is triggered when the chatroom details are fetched by the server.
onMessageReceive Any message received from the server triggers this method.
onLogout This callback method is invoked when the user logs out of the app.

Launch one-on-one/ Group user chat window

You can use this method to open the chat window for any particular user or a Group. This method launches the chat window for the user/ group specified and allows you to chat with them easily.

LaunchCometChat(final Activity activity, final boolean isFullscreen,
final String groupUserId, final boolean isGroup, ILaunchCallbacks callbacks)

e.g


cometChat.LaunchCometChat(this, isFullscreen, groupUserId, isGroup, new LaunchCallbacks(successObj => success(successObj), fail => failObj(fail), onChatroomInfo => ChatroomInfo(onChatroomInfo), onError => Error(onError), onLogout => Logout(onLogout), onMessageReceive => MessageReceive(onMessageReceive), onUserInfo => UserInfo(onUserInfo)) ); public void failObj(JSONObject p0) { //block of code } public void success(JSONObject p0) { //block of code } public void fail(JSONObject p0) { //block of code } public void ChatroomInfo(JSONObject p0) { //block of code } public void Error(JSONObject p0) { //block of code } public void Logout(JSONObject p0) { //block of code } public void MessageReceive(JSONObject p0) { //block of code } public void UserInfo(JSONObject p0) { //block of code }

Where LaunchCallbacks is same as above.

Parameters
Activity – Instance of the activity.
isFullScreen – A boolean value which when set to true launches the UI in full screen. Setting this value to false will launch the UI in a popup.
groupUserId – group id if you are launching a group window. User id of the user if u need to launch a user chat window.
isGroup – boolean value which needs to be set to true if you want to launch a group window. Else set it to false.
callbacks – This callback provides you with a set of methods to provide you information regarding the data fetched from the server.

The methods in the callback provide you with the following information

Method Details
successCallback This method is triggered once the request to launch CometChat is executed successfully
failCallback This is triggered when there is some issue when launching CometChat.
userInfoCallback This method is called when the user data is fetched from the server.
onGroupInfo This method is triggered when the chatroom details are fetched by the server.
onMessageReceive Any message received from the server triggers this method.
onLogout This callback method is invoked when the user logs out of the app.
  • Was this helpful?
  • Yes   No