Chat21 SDK Android
Quick start
With Chat21 you can add easily a realtime chat module to any existing mobile app or website. With chat21-android-sdk you can initialize and configure the chat module within an existing native Android app with a few lines of code.
Try our demo app
Our open-source demo app is a fully functional messaging app built upon material design principles. Download and build the demo app from GitHub to see what Chat21 can do.
ChatUI SDK
Below the description of the Chat21 User Interface SDK.
Open Conversations Activities
Show the conversation activity showing all the recent chat with:
ChatUI.getInstance().setContext(context); ChatUI.getInstance().openConversationsListActivity();
Open Messages Activities
Show the messages activity with a specified recipient with:
ChatUI.getInstance().setContext(context); ChatUI.getInstance().openConversationMessagesActivity("UID", "Andrea Leo");
Chat API
Send your first message
ChatManager.getInstance().sendTextMessage("UID", "Andrea Leo", "hello world!");
or with a callback:
ChatManager.getInstance() .sendTextMessage("UID", "Andrea Leo", "hello world!", null, new SendMessageListener() { @Override public void onBeforeMessageSent(Message message, ChatRuntimeException chatException) { Log.d(TAG, "onBeforeMessageSent called"); } @Override public void onMessageSentComplete(Message message, ChatRuntimeException chatException) { if (chatException == null) { Log.d(TAG, "Message sent: " + message.toString()); } else { Log.e(TAG, "Error sending message : ", chatException); } } });
Receive the messages
ConversationsHandler conversationsHandler = ChatManager.getInstance().getConversationsHandler(); ConversationsListener conversationsListener = new ConversationsListener() { @Override public void onConversationAdded(Conversation conversation, ChatRuntimeException e) { Log.d(TAG, "onConversationAdded" + conversation); } @Override public void onConversationChanged(Conversation conversation, ChatRuntimeException e) { Log.d(TAG, "onConversationChanged" + conversation); } @Override public void onConversationRemoved(ChatRuntimeException e) { Log.d(TAG, "onConversationRemoved"); } }; conversationsHandler.connect(conversationsListener); // Remember to remove the listener with conversationsHandler.removeConversationsListener(conversationsListener); //or with conversationsHandler.removeAllConversationsListeners();