- Integrate HubSpot chat into your mobile app to deliver real-time, in-app customer support.
- Leverage the bot and knowledge base tools to help deflect customer inquires when your support agents are unavailable.
- Alert users of new messages via push notifications.
- Customize the chat experience to align with your business’s brand and UI.
Set up and run the demo app
To set up the mobile chat SDK dependencies to your project:- Add your
google-services.json
in theapp/
folder, and ensure that thepackage_name
field in the file is set tocom.example.demo
. - Create your
hubspot-info.json
file in theapp/
folder. The full path of the file should beapp/src/main/assets/hubspot-info.json
. - Add the HubSpot package to your build gradle file:
- Sync your Android project with its gradle files.
- Build and run the app.
Install and configure the SDK
The SDK needs to be configured once per app launch. The most convenient time to configure the SDK is during app initialization. Start by getting an instance of theHubSpotManager
class, then call the configure
method
HubspotConfigError
class represents different errors when missing properties.
Open HubSpot chat view
The chat view can be opened byHubspotWebActivity
which extends the Activity
class. You can open it by using any of the following approaches:
- Directly calling
startActivity
via intent - Create any button type, then within an
onClick
listener of that button, open theHubspotWebActivity
. - Add
HubspotFloatingActionButton
in the file which handle the clicks and open theHubspotWebActivity
automatically.
onClick
listener of a button:
Identify users with the HubSpot visitor identification token
You can identify users by using the visitor identification API, detailed in this article. This API is best implemented in your own server project, where you can pass the identity token to your app based on whether suits your specific setup (i.e., passing a token in response to a visitor going through a login page as a result of a dedicated API that you own). Once a token is generated, it can be associated with a contact’s email address by callingHubspotManager.setUserIdentity(email, identityToken)
. This should be called before opening a chat view.
Add custom chat data properties
The SDK supports setting key-value pairs to keep track of data you might need to track while a chat session is open. You can set your own custom values, or declare common permission preferences such as photo or notification permissions. Use theHubspotManager.setChatProperties(key, value)
method and provide the associated key and value you want to set. This is best called before starting a chat, and will apply to all new chats. You could set an account status, or other identifiers when setting up your user. These will then appear in all chats opened for the remainder of the app launch.
For example, the following code would set permissions for camera, photo, notifications, and location data to "false"
.
Clear data on logout
The SDK stores in memory identification tokens, email address, and any properties set. The push token for the app is also associated with the current user, if applicable. You may want to clear this data when a user is logging out, or changing users in a multi user app. To clear this data, callHubspotManager.logout()
at an appropriate time in in your app.