Build a UI SDK App for Android
The UI SDK allows you to add Enhanced In-App Chat into your Android app with a ready-to-go user experience. Open a conversation with the UIClient class. You can customize the colors and strings so that the Messaging user interface looks natural in your app. Enhance the experience with push notifications, hidden pre-chat data, user verification, and other features.
This article applies to the following implementations:
| UI SDK | Core SDK |
|---|---|
| ✅ |
Step 1. Import the Classes
Most of the SDK classes are from these two packages:
1import com.salesforce.android.smi.core.* // For the core classes
2import com.salesforce.android.smi.ui.* // For the UI-related classesStep 2. Configure the UI Session
Create a UIConfiguration object using the config file that you previously downloaded from your org, or you can manually add the values from within this config file.
This example creates a random UUID for the conversation ID. However, if you want this conversation to persist even after the app is restarted, be sure to use the same conversation ID. Also, if you want to see this same conversation across multiple devices, in addition to using the same conversation ID, turn on user verification, which is described in the Enhance the Experience section.
Tip
Don’t use user IDs or other IDs as the ConversationID. Conversation IDs establish a permanent link with a user and are only available to the user who created it. Using a different existing ID instead of a unique ID can result in access issues or errors while developing or testing your Enhanced Chat integration. To pass existing IDs required for your flow, use the Pre-chat feature.
Note
OPTION 1: Configure Using the Config File
Once you’ve added the config.json file to your project, you can reference it from the code.
1// Create a Core configuration object
2val coreConfig = CoreConfiguration.fromFile(myContext, "configFile.json")
3
4// Generate a random conversation ID
5// (But be sure to use the SAME conversation ID if you want
6// to continue this conversation across app restarts or
7// across devices!)
8val conversationID = UUID.randomUUID()
9
10// Create a UI configuration object
11val config = UIConfiguration(coreConfig, conversationID)To learn how to download the config file from your org, see Configure an Enhanced In-App Chat Deployment in Salesforce Help. This file contains the Service API URL, the org ID, and the API name for the deployment. For example:
1{
2 "OrganizationId": "00ZZZ0000000Zzz",
3 "DeveloperName": "MyMessagingForInAppDeployment",
4 "Url": "https://zzzz.my.api.url.salesforce-scrt.com"
5}Note
OPTION 2: Configure Manually with Config Info
If you don’t want to use the config.json file in your project, you can configure the SDK manually using the Service API URL, the org ID, and the API name for the deployment.
1// Get a URL for the service API path
2val url = URL("URL_TO_MY_SERVICE_API")
3
4// Create a Core configuration object
5val coreConfig = CoreConfiguration(url, "ORG_ID", "API_NAME_OF_DEPLOYMENT")
6
7// Generate a random conversation ID
8// (But be sure to use the SAME conversation ID if you want
9// to continue this conversation across app restarts or
10// across devices!)
11val conversationID = UUID.randomUUID()
12
13// Create a UI configuration object
14val config = UIConfiguration(coreConfig, conversationID)Step 3. Add the View to Your App
Create a UIClient object. Open a conversation to show the UI.
1val uiClient = UIClient.Factory.create(config)
2uiClient.openConversationActivity(myContext)Without any additional code, the UI SDK automatically provides your customers with Messaging features such as pre-chat forms, bot support, file attachments, and estimated wait time. To learn how to configure these features in your org, visit our Enhanced Chat learning map.
Note
Step 4. Customize the UI
This step is optional.
Note
The UI SDK automatically brands the app with a default color scheme, provides icons for all UI elements, and uses default text for all UI labels. However, you can customize these elements with the UI SDK.
- To customize the color scheme in your app, create a color resource file in your app using the SDK’s token names. To learn more, see Customize Colors for Android.
- To customize any UI text, create a
strings.xmlresource file in your app using the SDK’s resource names. To learn more, see Customize Strings for Android. - To customize the icons and images used throughout the SDK, add a drawable asset to your project using the associated keyword. To learn more, see Customize Icons for Android.
Step 5. Enhance the Experience
This step is optional.
Note
You can enhance your users’ experience by adding push notifications, passing information to Salesforce about a verified user, sending hidden pre-chat fields, adjusting chat button visibility based on business hours, and more.
For enhanced features, see Enhance the Experience for Android.
Sample App
For an example app, see the UI SDK example in GitHub.