An Android SDK for integrating LiveChat functionality into your mobile application.
LiveChat: https://developers.livechat.com/docs/getting-started/installing-livechat/android-widget/
- Getting started
- Customer information
- Unread message counter
- UI Customization
- Clearing chat session
- Link handling
- Troubleshooting
- Advanced usage
- Migrating from v2.5.0 to 3.0.0
Add real-time customer support to your Android application with LiveChat's SDK. This guide covers installation, basic setup, and advanced features.
Note: 💡 The SDK is now Kotlin-based and uses the new package
com.livechatinc.chatsdk
. See migration notes if you are upgrading from v2.x.x.
The Android SDK is compatible with:
Android 5.0 (API level 21) or higher
Java 8 or higher
To install the SDK, first add the JitPack repository to your root build.gradle
:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Next, add dependency to your app's build.gradle
:
dependencies {
implementation 'com.github.livechat:chat-window-android:3.0.0'
}
Then, add Internet permission to AndroidManifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
You can initialize the SDK in the onCreate()
method of your Application
instance:
LiveChat.initialize("<LICENSE>", this)
The function below allows you to display a chat to a customer:
LiveChat.getInstance().show()
That's it! Your customers can start chatting with you now.
You can pre-fill the pre-chat form fields with customer information to provide your agents with more details about the customer. All information is optional.
The group ID defaults to 0
if not provided.
LiveChat.getInstance().setCustomerInfo(
"Joe", // Name
"[email protected]", // Email
"0", // Group ID, defaults to "0"
Collections.singletonMap("internalCustomerId", "ABC123") // Any additional custom parameters
)
Note: You should call the
setCustomerInfo()
beforeLiveChat.getInstance().show()
. To update customer properties when the chat has already loaded, recreate it withLiveChat.getInstance().destroyLiveChatView()
andLiveChat.getInstance().getLiveChatView()
.
To get notified about new messages in the chat, use com.livechatinc.chatsdk.src.domain.listeners.NewMessageListener
.
Set it wherever you want to react to a new message, for example, to increase the badge count.
LiveChat.getInstance().newMessageListener =
NewMessageListener { message, isChatShown ->
// Handle new message
}
While the chat appearance and language are managed through the application settings, you can customize the error view when chat cannot be loaded.
You can localize and change the text displayed in the error view by overriding string resources in your app's strings.xml
. All strings can be found in the GitHub repository.
You can also entirely override the default error view by including live_chat_error_layout.xml
in your app's layout resources.
Note: Your custom error view must contain a
View
withlive_chat_error_button
id when usingLiveChat.getInstance().show()
.
By default, activity will follow your activity's theme. To change this configuration, you can override the activity declaration in your app's AndroidManifest.xml
file.
The chat window uses WebView's cookies to store the session. To clear the chat session, call:
LiveChat.getInstance().signOutCustomer()
By default, links in the chat are opened in the customer's default browser. If you want to intercept the link and handle it in your app, provide your UrlHandler
.
LiveChat.getInstance().urlHandler =
UrlHandler { url ->
// Handle the URL in your app and return true if handled
return@UrlHandler false
}
You can set an error listener to monitor and handle issues related to loading the chat view. This allows you to capture and respond to errors in a centralized way. Common use cases include reporting errors to analytics platforms or implementing custom error-handling logic.
LiveChat.getInstance().errorListener = ErrorListener { error ->
// Handle the error
}
You can configure the logging level to help with debugging and troubleshooting. Set the desired level before initializing LiveChat:
Logger.setLogLevel(Logger.LogLevel.VERBOSE);
Refer to the Logger for all available log levels.
Note: Network calls require at least the
INFO
level.DEBUG
andVERBOSE
levels are more detailed.
If you want to react or track instances where the activity for file picking on the user device is not found, you can set a listener for this event:
LiveChat.getInstance().filePickerNotFoundListener = FilePickerActivityNotFoundListener {
// Handle the case when file picker activity is not found
}
The following features give you more control over the SDK integration. Note that they require additional implementation steps. If you decide to use any of these, please let us know about your use case — we would love to hear about it!
By default, after the LiveChat.getInstance().show()
view is initialized, it's kept in the application memory. This allows you to react to new messages, for example, display a counter for unread messages. To automatically free up memory when the chat is no longer visible, you can use LiveChatViewLifecycleScope
to control its lifecycle.
You should specify the scope when initializing the SDK:
LiveChat.initialize("<LICENSE>", this, lifecycleScope = LiveChatViewLifecycleScope.ACTIVITY)
Note: With the
ACTIVITY
scope, theNewMessageListener
only works while the chat is visible.
You can embed the LiveChatView
directly in your layout for more control over the chat window and its placement, instead of using LiveChat.getInstance().show()
. For full implementation details, refer to the LiveChatActivity.
Here is a short overview of the steps to embed the LiveChatView
in your layout:
Begin with adding <com.livechatinc.chatsdk.src.presentation.LiveChatView />
to your layout XML file.
During onCreate
of your Activity
or Fragment
, call:
liveChatView.attachTo(this)
This is required to properly handle the view's lifecycle, support file sharing, and launch links in the default external browser.
Provide LiveChatView.InitListener
when initializing the view:
liveChatView.init(initCallbackListener)
- The SDK is now Kotlin-based.
- The API is now streamlined and uses the
LiveChat
singleton. - The package changed to
com.livechatinc.chatsdk
. - Updated API for initializing and configuring the chat
- Edge-to-edge display support
- Enhanced error handling
dependencies {
implementation 'com.github.livechat:chat-window-android:3.0.0'
}
Note: With version 3 we no longer use "v" prefix
The new API uses LiveChat singleton instead of ChatWindowConfiguration and it's split into two parts: initialization and customer information setup.
Update activity declaration if needed
The old ChatWindowEventsListener
has removed. Some of the callbacks are no longer needed, the rest has been split into individual callbacks
onWindowInitialized()
-> removed for recommended integration. If you're embedding the view directly see Embed LiveChatView in your layout for detailsonChatWindowVisibilityChanged
-> removed recommended integration. If you're embedding the view directly see Embed LiveChatView in your layout for detailsonNewMessage
-> replaced with NewMessageListeneronRequestAudioPermissions
-> removedonError
-> replaced with ErrorListenerhandleUri
-> replaced with UriHandleronFilePickerActivityNotFound
-> FileChooserActivityNotFoundListener
For a complete example of implementation, please refer to the example app included in the repository.
v2 of the library is still available on JitPack. You can find documentation by selecting v2.x.x tag in the repository