The LivePerson SDK provides brands with a secure way to foster connections with their customers and increase app engagement and retention.

Use this Quick Start guide to get you up and running with a project powered by LivePerson. When done, you'll be able to send messages between an Android device and LiveEngage.

Prerequisites

Step 1: Install the Messaging SDK into your project

You can install the Mobile App Messaging SDK using a couple of different methods:


Option 1: Automatically add the SDK files using Gradle

You can use Gradle, an automation tool, to scale your projects effortlessly.

  1. In your project, locate and double-click Gradle Scripts > build.gradle (Module: app).

    Preview

  2. In the dependencies section, add:

    dependencies {
      implementation  "com.liveperson.android:lp_messaging_sdk:3.7.0"
    }
    

    Example: Build.gradle (Module: app) file

    apply plugin: "com.android.application"
    
    android {
        compileSdkVersion 26
        defaultConfig {
        applicationId "com.mybrand.app"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            }
        }
    }
    
    dependencies {
        implementation fileTree(dir: "libs", include: ["*.jar"])
        implementation "com.android.support:appcompat-v7:26.1.0"
        implementation "com.android.support.constraint:constraint-layout:1.0.2"
        testImplementation "junit:junit:4.12"
        androidTestImplementation "com.android.support.test:runner:1.0.1"
        androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
        // LivePerson SDK
        implementation  "com.liveperson.android:lp_messaging_sdk:3.7.0"
    }
    

Option 2: Manually copying the SDK files to your project

  1. Download the latest SDK package.
  2. Extract the file to a folder on your computer. The package contains all of the files you need to add to your project. Also in the package, you get a sample app that demonstrates how to use the SDK.
  3. In your Android Studio project, go to File > New > Import module.
  4. Navigate to the folder where you extracted the SDK, select the lp_messaging_sdk module, and then click Finish.
  5. In your build.gradle of your app, and in the android section, make sure the compileSdkVersion is at least version 26:
    android {
       compileSdkVersion 26
       buildToolsVersion "26.0.0"
    repositories {
      	flatDir {
        	   dirs project(":lp_messaging_sdk").file("aars")
       }
    }
    
  6. In the defaultConfig section, make sure the minSDKVersion is set 19:
    defaultConfig {
        applicationId "com.mybrand.app"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    
  7. In the dependencies section, add:
    compile project(":lp_messaging_sdk")
    

    Build.gradle file example:

    apply plugin: "com.android.application"
    
    android {
        repositories {
            flatDir {
                dirs project(":lp_messaging_sdk").file("aars")
            }
        }
       compileSdkVersion 26
       buildToolsVersion "26.0.0"
        defaultConfig {
            applicationId "com.mybrand.app"
            minSdkVersion 19
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
    
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: "libs", include: ["*.jar"])
        androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
            exclude group: "com.android.support", module: "support-annotations"
        })
        compile "com.android.support.constraint:constraint-layout:1.0.2"
        compile "com.google.firebase:firebase-messaging:11.6.0"
        compile "com.google.firebase:firebase-core:11.6.0"
    
    
        testCompile "junit:junit:4.12"
        //Liveperson SDK
        compile project(path: ":lp_messaging_sdk")
    }
    
    apply plugin: "com.google.gms.google-services"
    
  8. In your settings.gradle of your app, add:
    include ":lp_messaging_sdk"
    

Step 2: Integrate code for basic deployment

  1. Add permissions to your app’s AndroidManifest.xml file:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
  2. Add imports to your class imports section:

    import com.liveperson.api.LivePersonCallback;
    import com.liveperson.infra.InitLivePersonProperties;
    import com.liveperson.infra.callbacks.InitLivePersonCallBack;
    import com.liveperson.messaging.TaskType;
    import com.liveperson.messaging.model.AgentData;
    import com.liveperson.messaging.sdk.api.LivePerson;
    

Step 3: Initialize the Messaging SDK

Before you can show a conversation, you must initialize the Messaging SDK.

If you want to use the Monitoring API, you must initialize the Messaging SDK with Monitoring Params.

  1. Set your app ID and view controller. Provide your APP_ID as a string your application's class.

    private static final String APP_ID = "com.mybrand.app";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    
  2. Select your choice of authentication for initializing the SDK instance.

    For more details on Code Flow and Implicit Flow for the Mobile SDK, see How It Works.

    • Code Flow (authenticated)

      The LivePerson back-end verifies the authentication token sent by the SDK with your system servers. If the key cannot be verified on your company’s backend servers, this call fails.

      LPAuthenticationParams().setAuthKey("yourAuthCode").
      

      Tip: Alternatively, when using this method, you can also set a special redirect URL when authenticating by calling:

      lpAuthenticationParams.setHostAppRedirectUri("yourRedirectUrl")
      
    • Implicit Flow (authenticated)

       LPAuthenticationParams().setHostAppJWT("yourJwt")
      

      Once the Authentication key expires, you get notified with a callback / local intent void onTokenExpired().

      To re-connect with a new Authentication key, use reconnect(LPAuthenticationParams lpAuthenticationParams)

      Errors while trying to connect uses callback: void onError(TaskType type, String message);

    • Unauth Flow

       String brandID = "53949244";
       String appInstallID = "46bcf782-feee-490d-861d-2b5feb4437c8";
      
    • Signup Flow

      String brandID = "62219232";
      
  3. Show the conversation view. If your system implementation involves an authentication step, you must call our showConversation method provided by the LPMessagingSDK instance. It pushes a new navigation stack containing the conversation view. For more details on Activity mode and Fragment mode, see Authentication.

    Choose an authentication method:

    • Activity mode
      LivePerson.showConversation(Activity activity, LPAuthenticationParams lpAuthenticationParams, ConversationViewParams params);
      
    • Fragment mode (Attach the returned fragment to a container in your activity)
      LivePerson.getConversationFragment(LPAuthenticationParams lpAuthenticationParams, ConversationViewParams params);
      

      Tip. When using fragment mode, you could use the provided SDK callbacks in your app in order to implement functionalities such as menu items, action bar indications, agent name, and typing indicator.

  4. Initialize your application. We have provided examples to use to help you get started. The demo account has basic features available for demonstrating the Conversational Commerce experience in the LiveEngage console.

    • Code Flow
      public void startCodeFlow(View v) {
          String brandID = "62219232";
          final String authCode = "k16336";
          LivePerson.initialize(this, new InitLivePersonProperties(brandID, APP_ID, new InitLivePersonCallBack() {
              @Override
              public void onInitSucceed() {
                  LPAuthenticationParams lpAuthenticationParams = new LPAuthenticationParams(LPAuthenticationParams.LPAuthenticationType.AUTH);
                  lpAuthenticationParams.setAuthKey(authCode);
                  LivePerson.showConversation(MainActivity.this, lpAuthenticationParams, new ConversationViewParams());
              }
      
              @Override
              public void onInitFailed(Exception e) {
              }
          }));
      }
      
    • Implicit Flow

      public void startImplicitFlow(View v) {
          String brandID = "42391995";
          final String jwt = "eyJhbGciOiJSUzI1NiJ9.eyAgInN1YiI6ICJoZWxsbyIsICAiaXNzIjogImh0dHBzOi8vTFAtQXV0aC5jb20iLCAgImV4cCI6MTU1Mzc5NDAyMSwgICJpYXQiOjE1NTM3OTM0MjF9.GP0iCe1k3aQbWHp-FYKhpfK-MZqktQ8pByTTF5lAHTelCyDAxhgHyMIq5J9mJnSoIdTlUbmscRHpy2MCop-AlYx5Sz66y1aX38AD8Rat1k_SnbPNbvbEysomb_SjxZ3uleN_OCzrSqGJrLXP6yIN2UiuuvKM62i-e-aQVIWzIXWMxjgmH9n_ZUOkgq_0jY3Me8r78dKsitc-jvzGzbasv81u40fR-7Y-ViOZliFOLjVBl2VWCbgcrGerLUyWVJQW69Hn3TlvvVpSVZk-IUU8hpYorcItIb-XNV2mOVkuZmzlGo7a1nIhJCCWzP5qaQvCCecSHTTHbcROwwE7dk6vKg";
          LivePerson.initialize(this, new InitLivePersonProperties(brandID, APP_ID, new InitLivePersonCallBack() {
              @Override
              public void onInitSucceed() {
                  LPAuthenticationParams lpAuthenticationParams = new LPAuthenticationParams(LPAuthenticationParams.LPAuthenticationType.AUTH);
                  lpAuthenticationParams.setHostAppJWT(jwt);
                  LivePerson.showConversation(MainActivity.this, lpAuthenticationParams, new ConversationViewParams());
              }
      
              @Override
              public void onInitFailed(Exception e) {
              }
          }));
      }
      
    • Unauth Flow

      public void startUnauthFlow(View v) {
          String brandID = "53949244";
          String appInstallID = "46bcf782-feee-490d-861d-2b5feb4437c8";
          final MonitoringInitParams monitoringInitParams = new MonitoringInitParams(appInstallID);
          LivePerson.initialize(this, new InitLivePersonProperties(brandID, APP_ID, monitoringInitParams, new InitLivePersonCallBack() {
              @Override
              public void onInitSucceed() {
                  LPAuthenticationParams lpAuthenticationParams = new LPAuthenticationParams(LPAuthenticationParams.LPAuthenticationType.UN_AUTH);
                  LivePerson.showConversation(MainActivity.this, lpAuthenticationParams, new ConversationViewParams());
              }
      
              @Override
              public void onInitFailed(Exception e) {
              }
          }));
      }
      
    • Signup Flow

      public void startSignupFlow(View v) {
          String brandID = "62219232";
          LivePerson.initialize(this, new InitLivePersonProperties(brandID, APP_ID, new InitLivePersonCallBack() {
              @Override
              public void onInitSucceed() {
                  LPAuthenticationParams lpAuthenticationParams = new LPAuthenticationParams(LPAuthenticationParams.LPAuthenticationType.SIGN_UP);
                  LivePerson.showConversation(MainActivity.this, lpAuthenticationParams, new ConversationViewParams());
              }
      
              @Override
              public void onInitFailed(Exception e) {
              }
          }));
      }
      
    Element Description
    brandID Your LivePerson account ID. If you don’t have one, please contact your LivePerson representative.
    APP_ID Your application ID (com.mybrand.app), which is used in the registerLPPusher method.
    onInitSuccess Callback that indicates the init process has finished successfully.
    onInitFailed Callback that indicates the init process has failed.

    Example implementation:

    private static final String APP_ID = "com.mybrand.app";
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    
    public void startCodeFlow(View v) {
        String brandID = "62219232";
        final String authCode = "k16336";
        LivePerson.initialize(this, new InitLivePersonProperties(brandID, APP_ID, new InitLivePersonCallBack() {
            @Override
            public void onInitSucceed() {
                LPAuthenticationParams lpAuthenticationParams = new LPAuthenticationParams(LPAuthenticationParams.LPAuthenticationType.AUTH);
                lpAuthenticationParams.setAuthKey(authCode);
                LivePerson.showConversation(MainActivity.this, lpAuthenticationParams, new ConversationViewParams());
            }
    
            @Override
            public void onInitFailed(Exception e) {
            }
        }));
    }
    

    Make sure that the init process, from the onInitSucceedcallback, finished successfully.

Next Steps

Congratulations! You're all set.

You can now do any of the following:

  • Configure the SDK. You can register for LivePerson events related to the conversation, determine the layout of messaging with the app, configure Proguard, or define the backup rules for auto backup and restore.
  • Configure push notifications. Push and local notifications are a key factor that makes the experience better for consumers - they never have to stay in your app or keep the window open as they will get a proactive notification as soon as a reply or notice is available.
  • Enable features in your AndroidManifest.xml file. If you have vibrate on new message, photo sharing, or audio messaging enabled, you must add the following to your app's AndroidManifest.xml file.
  • Customize and brand the SDK. You can customize the look and feel of the conversation screen with your branding.xml file. Additionally, you can configure the style of the message EditText in your styles.xml file.