Loop Android SDK Setup

About this SDK

Loop Android SDK offers a convenient way to launch surveys in your mobile app with custom surveys for the mobile use case, while minimizing the data the user is required to enter. This document explains how to install and configure the SDK for Android smartphones.

Setting up an Embedded Feedback Channel

If you haven’t already, go to the Channels page and create an Embedded Pulse Channel. Create a new survey or choose an existing survey. This will generate an app ID for your app.

Installing Loop SDK

The Loop Android SDK will soon be available on JCenter. Add the following dependencies to your app’s build.gradle file:

implementation 'com.benbria.loop.mobilesdk:base:1.0.0'
implementation 'com.benbria.loop.mobilesdk:pulse:1.0.0'

The Pulse Android SDK requires Android 5.0 (API 21) or higher.

Initializing the SDK

Find the embedded app ID for the Embedded Pulse Channel, and pass it as a parameter to the initialize method, as shown below.

If you already have a class extending the Android Application class, insert the following line into the onCreate() method:

Loop.initialize(this, "appId");

If you don’t have a custom Application class, create one like the following:

public class MyApplication extends Application {     @Override public void onCreate() {         super.onCreate();         Loop.initialize(this, "appId");    } }

You will also need to update your AndroidManifest.xml to use your new class:


Setting the Location

Set the location by providing its number (short code) any time before launching the survey Activity. If the survey Activity is launched without setting the location, the user will be asked to pick a location before the survey.


Providing Contact Information

Some survey responses result in Loop conversations if the customer decides to open a conversation by leaving contact information. You may already have the essential contact information such as the customer name, email address and phone number. You can pass these values to Loop Pulse, so that the customer won’t need to enter them again, if they decide to be contacted.

Create a Contact object. All fields are optional.

Contact contact = new Contact.Builder()     .withName("John Smith")     .withEmail("john.smith@example.com")     .withPhone("+16135551234")    .build();

Any time before launching the Pulse survey Activity, set this contact to the Pulse client:


Adding Custom Field Entries

The Loop platform supports custom fields in a variety of types including text, number and date. Custom fields are metadata that are saved when the customer opens a conversation. You can add custom field entries as key-value pairs where the key is the custom field short code.

Create custom field entries:

CustomFieldEntries entries = new CustomFieldEntries.Builder()     .addEntry("orderDate", new Date())     .addEntry("orderId", "1827012")     .build();

Any time before launching the Pulse survey Activity, set the entries to the Pulse client:


Initializing and Displaying the Survey Activity

You can show the Pulse survey Activity any time in your application, from any Context. You can launch the survey Activity when the user agrees to take the survey by tapping on a button.

The survey has web components that need to be loaded, so in order to offer a better experience to the user, before showing the survey Activity, we recommend calling the preparePulseActivity(Context) method. You can call this method in the onCreate() method of your Activity.

// `this` is a Context. Loop.client().preparePulseActivity(this);

Then you can call the following method any time to show the Pulse survey Activity:

// `this` is a Context. Loop.client().showPulseActivity(this);

The survey Activity will be dismissed when the user completes the survey or taps on the close or system back buttons.

You can also dismiss the Pulse survey Activity by calling this method:

// `this` is a Context. Loop.client().hidePulseActivity(this);

You can set an event listener to get notified when the Pulse survey Activity is dismissed for any reason:

Loop.client().setPulseSurveyResultListener(new PulseSurveyResultListener() {    @Override    public void onSurveyResult(Pulse.SurveyResult result) {       ...    } });

result is an enum with following options:

  • COMPLETE: used when the survey Activity is closed upon successful survey completion
  • DISMISSED: used when the user dismissed the survey Activity.
  • CANCELED: used when the survey Activity is dismissed by the app, calling hidePulseActivity().

Before launching the survey Activity, we recommend setting the location and providing contact information (if available), so that Loop is not going to ask for the same data again and let the user complete the survey as fast as possible.

Did this answer your question?