Step 1 - Creating initial views

  • In order to get some basic data from the user, let’s create some initial views on our main activity / an activity of your choosing (more data can be used in order to initialize the SDK, during this guide, we’ll use some basic name features only).


Step 2 - Integrate LivePerson Android SDK within your Project (Gradle)

  1. In your project files in the left sidebar, locate Gradle Scripts > build.gradle (Module: app), then double-click the file to open it in the editor.


  1. In the dependencies section, insert the following line:
dependencies {
    implementation  ''

Example: Build.gradle (Module: app) file

apply plugin: ''

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.shaym.liveperson.androidsdk"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner ""
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation ''
    implementation ''
    testImplementation 'junit:junit:4.12'
    androidTestImplementation ''
    androidTestImplementation ''
    // LivePerson SDK
    implementation  ''

Step 3 - Manifest modifications

  1. Add the following permission to your app’s AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Vibrate on new incoming msg (required if enabled):

<uses-permission android:name="android.permission.VIBRATE"/>

For Photo Sharing (required if enabled):

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Step 4- Liveperson Events

  1. Intents Handler - In order to listen to LivePerson basic messaging events (via BroadcastReceiver) and respond via callback accordingly, we will have to add a class that will handle those events.
  • Create a class and name it - IntentsHandler (or any other name of your choosing)
public class IntentsHandler {

   private Context mContext;
   private BroadcastReceiver mLivePersonReceiver;

   public IntentsHandler(Context ctx){
       this.mContext = ctx;
  • Create a function named registerToLivePersonEvents and init the broadcast receiver we declared earlier:
public void registerToLivePersonEvents(){
           .registerReceiver(mLivePersonReceiver, LivePersonIntents.getIntentFilterForAllEvents());
  • In this example we will listen to all events via the intentfilter shown above, but you can create your own specific intent filter as well.

  • Create a function named createLivePersonReceiver and handle the events accordingly, this is a wide example of handling most of the events. You can read more about Liveperson events here.

Here is an example of a function which handles some LivePerson events:

private void createLivePersonReceiver() {
   if (mLivePersonReceiver != null){
   mLivePersonReceiver = new BroadcastReceiver(){

       public void onReceive(Context context, Intent intent) {

           Log.d(TAG, "Got LP intent event with action " + intent.getAction());
           switch (intent.getAction()){
               case LivePersonIntents.ILivePersonIntentAction.LP_ON_AGENT_AVATAR_TAPPED_INTENT_ACTION:

               case LivePersonIntents.ILivePersonIntentAction.LP_ON_AGENT_DETAILS_CHANGED_INTENT_ACTION:
                   AgentData agentData = LivePersonIntents.getAgentData(intent);


Following the function above you will have to add a function that will act according to the specific use-case, for example:

private void onAgentAvatarTapped(AgentData agentData) {
   showToast("on Agent Avatar Tapped - " + agentData.mFirstName + " " + agentData.mLastName);

Step 5- Messaging activity

  1. Create a messaging activity that will launch the activity session, in this tutorial we will demonstrate a basic initialization of the LivePerson SDK in Activity mode though you can also initialize it in Fragment mode and use different features while doing so.

  2. Basic members:

public class MainActivity extends AppCompatActivity {
 // Consumer name inputs
   private EditText fnameInput;
   private EditText lnameInput;
   private Button startConvBtn;
 // Brand login details
   private final String brandID = "82055668";
// Project’s package
   private final String appID = "com.shaym.sdk28";
 // Intent Handler
   private IntentsHandler mIntentsHandler;
  1. onCreate:
protected void onCreate(Bundle savedInstanceState) {
// IntentsHandler is the object we introduced in the previous section of this tutorial
   mIntentsHandler = new IntentsHandler(this);
// init basic UI views
// Init the button listener
  1. init Button function:
private void initOpenConversationButton() {
   startConvBtn = (Button) findViewById(;
   startConvBtn.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
          // This will check if we already in a conversation
           if (LivePerson.isValidState()) {
           else {
// Push - later in this tutorial
               initActivityConversation(); // The conversation activity
  1. init Activity conversation:

A few notes on this step:

  • In this step we will initialize the SDK, but only if we're not already in a valid state (we checked for that in the previous section).

  • We are using the brandID and appID during this which we declared those in the top of this class).

  • If the initialization is a success, we will call the openActivity method

  • GCMRegistration is a service we will implement in order to use push notifications, we will touch on that later on in this tutorial.

private void  initActivityConversation() {

     LivePerson.initialize(MainActivity.this, new InitLivePersonProperties(brandID, appID, new InitLivePersonCallBack() {
         public void onInitSucceed() {
             // you can't register pusher before initialization
             runOnUiThread(new Runnable() {
                 public void run() {
         public void onInitFailed(Exception e) {
             runOnUiThread(new Runnable() {
                 public void run() {
                     Toast.makeText(MainActivity.this, "Init Failed", Toast.LENGTH_SHORT).show();
  1. The openActivity function

Here is where we use LivePerson SDK’s showConversation method. In this example we didn’t use an authentication parameter, though you can definitely use one if needed (using the setPhoneNumber field).

private void openActivity() {
   LivePerson.showConversation(MainActivity.this,  new LPAuthenticationParams().setAuthKey(""), new ConversationViewParams(false));
   ConsumerProfile consumerProfile = new ConsumerProfile.Builder()

Step 6- Configuring Push Notifications

Firebase Configuration

Firebase Config

  1. Enter Google Firebase console

  2. Enter your app’s package name and click on ‘Register App’

Register App

Register App

  1. Download the JSON config file and drag it into your project level in android studio.

  2. Follow the gradle instructions below (make sure there are no duplicates), and click ‘Finish’.

Gradle Setup

Add the following lines in your app.gradle dependencies section:

compile ''
compile ''

Change the 'multiDexEnabled' under the android tag to true

multiDexEnabled true

LiveEngage Configuration

  1. Connect to your account via LiveEngage, click on the campaigns tab. than choose 'Data Sources'

Data Sources

Data Sources Step 2

  1. Click Manage, on the right of 'Mobile app management' tab
  1. Click Add new, in order to add your app to the mobile campaign

App Key

  1. Fill in your mobile package name under mobile app name, Google Firebase Legacy API key under push notification API key.

Then click 'Create app'

Create App

  1. Package Name (From the firebase console):

Firebase General

  1. Legacy Key:

Firebase Key

Project Configuration

  1. Add the following services + receiver under the application tag:
               <action android:name=""/>
       <!--This service is used to receive and register the token when it is refreshed-->
               <action android:name=""/>

       <receiver android:name=".push.NotificationUI$BadgeBroadcastReceiver">
               <action android:name="ACTION_LP_UPDATE_NUM_UNREAD_MESSAGES_ACTION"/>

Note: After you've added the services you will have to create the classes to fit those services. Create new classes called: MyFirebaseMessagingService, MyFirebaseInstanceIDService, Firebase registrationintentservice, NotificationUI (or choose your own names for these classes).

Change the path of the services according to the classes you just created.

  1. Add the following permission to your app’s AndroidManifest.xml file:
<uses-permission android:name="" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
  1. Following the handleGCMRegistration(MainActivity.this); call we added at the init stage, add the following function to your messaging activity call in order to register to the pusher:
private void handleGCMRegistration(Context ctx) {
   Intent intent = new Intent(ctx, FirebaseRegistrationIntentService.class);
  1. Following the removeNotification(); call we added at the Showconversation stage, add the following function in order to hide the push message when entering the conversation view:
private void removeNotification() {
  1. NotificationUI is the class that will enable us to present and handle the push to the UI.

Here is a simple example:

public class NotificationUI {

   private static final String TAG = NotificationUI.class.getSimpleName();
   public static final int NOTIFICATION_ID = 143434567;
   public static final String PUSH_NOTIFICATION = "push_notification";

   public static void showNotification(Context ctx, PushMessage pushMessage) {
       NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).
               setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS).
               setStyle(new NotificationCompat.InboxStyle()

                       .addLine("Unread messages : " + LivePerson.getNumUnreadMessages(pushMessage.getBrandId()))


       if (Build.VERSION.SDK_INT >= 21) {
           builder = builder.

   public static void hideNotification(Context ctx){

   private static NotificationManager getNotificationManager(Context ctx) {
       return (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

   private static PendingIntent getPendingIntent(Context ctx) {
       Intent showIntent = new Intent(ctx, MainActivity.class);
       showIntent.putExtra(PUSH_NOTIFICATION, true);

       return PendingIntent.getActivity(ctx, 0, showIntent, PendingIntent.FLAG_UPDATE_CURRENT);

   /************************ Example of Icon Badge - For Samsung *******************************/
   public static void setBadge(Context context, int count) {

        SharedPreferences.Editor editor = context.getSharedPreferences("liveperson", MODE_PRIVATE).edit();
        SharedPreferences prefs = context.getSharedPreferences("liveperson", MODE_PRIVATE);

       int current = prefs.getInt("count", 0);
       if (current == 0 || count == 1)
           current += count;
           current = count;
       editor.putInt("count", current);

       String launcherClassName = getLauncherClassName(context);
       if (launcherClassName == null) {
       Intent intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE");
       intent.putExtra("badge_count", current);
       intent.putExtra("badge_count_package_name", context.getPackageName());
       intent.putExtra("badge_count_class_name", launcherClassName);

   public static String getLauncherClassName(Context context) {

       PackageManager pm = context.getPackageManager();

       Intent intent = new Intent(Intent.ACTION_MAIN);

       List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
       for (ResolveInfo resolveInfo : resolveInfos) {
           String pkgName = resolveInfo.activityInfo.applicationInfo.packageName;
           if (pkgName.equalsIgnoreCase(context.getPackageName())) {
       return null;
    /* Listen to changes in unread messages counter and updating icon badge*/
   public static class BadgeBroadcastReceiver extends BroadcastReceiver{

       public BadgeBroadcastReceiver(){}

       public void onReceive(Context context, Intent intent) {
           int unreadCounter = intent.getIntExtra(LivePerson.ACTION_LP_UPDATE_NUM_UNREAD_MESSAGES_EXTRA, 0);
           NotificationUI.setBadge(context, unreadCounter);

Services Classes

The following services are an extension of Google’s Firebase cloud messaging services, you can read more about them here.


We call this service from our messaging activity when we init the SDK and want to register for the pusher for the first time (or every time we init), here is a simple example:

public class FirebaseRegistrationIntentService extends IntentService {

   public static final String TAG = FirebaseRegistrationIntentService.class.getSimpleName();

   public FirebaseRegistrationIntentService() {

   protected void onHandleIntent(Intent intent) {
       Log.d(TAG, "onHandleIntent: registering the token to pusher");
       String token = FirebaseInstanceId.getInstance().getToken();
       // Register to Liveperson Pusher
       String account = "82055668";
       String appID = "com.shaym.sdk28";
       LivePerson.registerLPPusher(account, appID, token);

Enter your account number as account, and your package name as appID in order to register to the pusher, as seen in the example above. Notice the token we are getting from the FirebaseInstanceId. This is sent to the LivePerson pusher and integrated into your LivePerson account.


This service is always running in the background and handles incoming messages, here's a simple example:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG = "MyFirebaseMsgService";

   public void onMessageReceived(RemoteMessage remoteMessage) {
             // TODO(developer): Handle FCM messages here.
       Log.d(TAG, "From: " + remoteMessage.getFrom());
       // Check if message contains a data payload.
       if (remoteMessage.getData().size() > 0) {
           Log.d(TAG, "Message data payload: " + remoteMessage.getData());

           // Send the data into the SDK
           String account = "82055668";
           PushMessage message = LivePerson.handlePushMessage(this, remoteMessage.getData(), account, false);

           //Code snippet to add push UI notification
           if (message != null){
               NotificationUI.showNotification(this, message);

       // Check if message contains a notification payload.
       if (remoteMessage.getNotification() != null) {
           Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());




This is a pretty simple service that will be called every time Google’s token is refreshed so you can re-register to the push service.

Simple example:

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

  private static final String TAG = "MyFirebaseIIDService";

  public void onTokenRefresh() {
     // Get updated InstanceID token.
     Intent intent = new Intent(this, FirebaseRegistrationIntentService.class);


Handle Push

In order to handle a scenario when a push message is clicked on, we will have to implement a push handler on our messaging activity’s onCreate function.

Add the following call into the bottom of your onCreate function to achieve this:


Then, add the following function into the messaging activity. This will check if the intent which opened the app came from a push notification. If it does, the function will automatically direct the user to the conversation screen.

private void handlePush(Intent intent) {
   boolean isFromPush = intent.getBooleanExtra(NotificationUI.PUSH_NOTIFICATION, false);
   //Check if we came from Push Notification
   if (isFromPush) {
               if (LivePerson.isValidState()){

You should also add to your messaging activity in order to clear all pushes once the conversation screen has been clicked:

private void clearPushNotifications() {
   ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(NotificationUI.NOTIFICATION_ID);