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 three 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 and you have a ready-to-go chat feature implemented in your android application.


launchCometChat(final Activity context, final boolean isFullscreen, final LaunchCallbacks callbacks)

cometChat.launchCometChat(MainActivity.this, true, new LaunchCallbacks() { @Override public void successCallback(JSONObject jsonObject) { } @Override public void failCallback(JSONObject jsonObject) { } @Override public void userInfoCallback(JSONObject jsonObject) { } @Override public void chatroomInfoCallback(JSONObject jsonObject) { } @Override public void onMessageReceive(JSONObject jsonObject) { } @Override 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.
chatroomInfoCallback 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 user chat window

You can use this method to open the chat window for any particular user. This method launches the chat window for the user specified and allows you to chat with him/her easily.

launchCometChat(final Activity activity, final boolean isFullscreen,
final String groupUserId, final boolean isGroup, final LaunchCallbacks callbacks)

cometChat.launchCometChat(MainActivity.this, true,"12",false, new LaunchCallbacks() {
                    @Override
                    public void successCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void failCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void userInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void chatroomInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void onMessageReceive(JSONObject jsonObject) {

                    }

                    @Override
                    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.
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.
chatroomInfoCallback 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 group chat window

This method can be used to open the chat window to any particular group.

launchCometChat(final Activity activity, final boolean isFullscreen,
final String groupUserId, final boolean isGroup, final LaunchCallbacks callbacks)

cometChat.launchCometChat(MainActivity.this, true,"21",true, new LaunchCallbacks() {
                    @Override
                    public void successCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void failCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void userInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void chatroomInfoCallback(JSONObject jsonObject) {

                    }

                    @Override
                    public void onMessageReceive(JSONObject jsonObject) {

                    }

                    @Override
                    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.
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.
chatroomInfoCallback 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