Skip to main content

Survey Sparrow Android SDK

SurveySparrow Android SDK enables you to collect feedback from your mobile app. Embed the Classic, Chat & NPS surveys in your Android application seamlessly with few lines of code.

Mobile SDK share channel is only available from SurveySparrow Premium plan onwards.

Features

  1. Fully customizable pre-build Activity to take feedback whenever & wherever you want.
  2. Fragment to integrate the feedback experience anywhere in your app.
  3. Schedule Surveys to take one-time or recurring feedbacks.

SDK integration (Require API level 19)

Add it in your root build.gradle at the end of repositories:

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Add the following line to your app modules build.gradle file inside dependencies

implementation 'com.github.surveysparrow:surveysparrow-android-sdk:0.4.7'

The SDK need Internet access to fetch survey & submit answers. Add the following permissions to AndroidManifest.xml file

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

Take feedback using Activity

Take feedback using our pre-build Activity and get the response after submission by overriding the calling Activity's onActivityResult method.

SurveySparrow Android SDK full-screen view

Create a SsSurvey Object

Create SDK token by from the share page of your survey in the SurveySparrow web app and use that token to create the SsSurvey Object.

SsSurvey survey = new SsSurvey("your-company-domain", "sdk-token");

Create a SurveySparrow object

Create a SurveySparrow object to configure and start the feedback Activity.

SurveySparrow surveySparrow = new SurveySparrow(this, survey)
.setActivityTheme(R.style.AppTheme)
.setAppBarTitle(R.string.app_name)
.enableBackButton(true)
.setWaitTime(2000)
.setValidateSurveyListener(this); // add this if you are using OnSsValidateSurveyEventListener in your activity

Start the feedback Activity

surveySparrow.startSurveyForResult(SURVEY_REQUEST_CODE);

Handle response

Override the onActivityResult to handle the response.

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SURVEY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
// Convert the response to JSON.
JSONObject responses = SurveySparrow.toJSON(data.getData().toString());

// Add your logic here...
} else {
// The activity closed before completing the survey.
}
}
}

Handle survey validation

Override the onSsValidateSurvey to handle the survey validation.

@Override
public void onSsValidateSurvey(JSONObject s) {
Log.v(LOG_TAG, "survey validation json" + s.toString());
}

Embed survey in your Activity

Embed the feedback experience to your Activity using the SsSurveyFragment. Then you can implement the OnSsResponseEventListener interface to handle response after submission.

Implement OnSsValidateSurveyEventListener interface to handle validation of survey

SurveySparrow Android SDK embed view

Create SsSurvey object

SsSurvey survey = new SsSurvey("your-company-domain", "sdk-token");

Embed survey in your Activity

For versions below 0.4.0

SsSurveyFragment surveyFragment = new SsSurveyFragment(survey);

For other versions

SsSurveyFragment surveyFragment = new SsSurveyFragment();
surveyFragment.setValidateSurveyListener(this); // add this if you are using OnSsValidateSurveyEventListener in your activity
surveyFragment.setSurvey(survey);

Start the fragment transaction

FragmentManager fragmentManager = this.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.surveyContainer, surveyFragment);
fragmentTransaction.commit();

Get survey response

Implement the OnSsResponseEventListener interface in your Activity and override the onSsResponseEvent method to get and handle the response.

public class YourActivity extends AppCompatActivity implements OnSsResponseEventListener {
// Your code...
@Override
public void onSsResponseEvent(JSONObject response) {
// Handle response here
}
// Your Code...
}

Handle survey validation

Override the onSsValidateSurvey to handle the survey validation.

@Override
public void onSsValidateSurvey(JSONObject s) {
Log.v(LOG_TAG, "survey validation json" + s.toString());
}

Schedule Surveys

Ask the user to take a feedback survey when they open your app/Activity/page after a period of time.

SurveySparrow Android SDK scheduling

Create SsSurvey object

SsSurvey survey = new SsSurvey("your-company-domain", "sdk-token");

Create and schedule the feedback activity.

surveySparrow = new SurveySparrow(this, survey)
.setActivityTheme(R.style.AppTheme)
.setAppBarTitle(R.string.app_name)
.enableBackButton(true)
.setWaitTime(2000)
.setValidateSurveyListener(this); // add this if you are using OnSsValidateSurveyEventListener in your activity

// Schedule specific config
.setStartAfter(TimeUnit.DAYS.toMillis(3L))
.setRepeatInterval(TimeUnit.DAYS.toMillis(5L))
.setRepeatType(SurveySparrow.REPEAT_TYPE_CONSTANT)
.setFeedbackType(SurveySparrow.SINGLE_FEEDBACK);

surveySparrow.scheduleSurvey(SURVEY_SCHEDULE_REQUEST_CODE);

Handle response

Handle response the same way as Take feedback using Activity

Handle survey validation

Handle survey validation the same way as Handle survey validation

Clear a schedule

You can clear a schedule by calling the surveySparrow.clearSchedule() method.

How scheduling works

We will show a customized prompt to take a feedback survey whenever the scheduleSurvey method called after the setStartAfter time and if the user declines to take the survey we will show the prompt after the setRepeatIntervalTime.

Example use case: Add the above code to onStart method of your launcher Activity to ask the user to take a feedback survey 3 days after the user starts using your app, and if the user declines to take the survey we will continue to prompt at an interval of 5 days. If the user takes and complete the survey once we will not ask again.

*You can only create one schedule per token. Create multiple tokens if you want to create multiple schedules for same survey.

NPS Survey

Survey type can be changed to NPS using setSurveyType(SurveySparrow.NPS) on an SsSurvey instance. You can also pass email as a custom param.

Reference

SsSurvey

Nested classes

CustomParam : To hold custom params.

Constructor - CustomParam(CharSequence name, CharSequence value)

Public constructors

SsSurvey(CharSequence domain, CharSequence surveyToken) : Create SsSurvey with domain & token

SsSurvey(CharSequence domain, CharSequence surveyToken, CustomParam[] customParams) : Create SsSurvey with domain, token & custom params.

SsSurvey(CharSequence domain, CharSequence surveyToken, CustomParam[] customParams, HashMap properties) : Create SsSurvey with domain, token , custom params and with traslate language code.

Public methods

ReturnPrototype
SsSurveyaddCustomParam(CustomParam customParam): add custom param by passing a SsSurvey.CustomParam object.
SsSurveyaddCustomParams(CustomParam[] customParams): add custom params by passing SsSurvey.CustomParam object array.
SsSurveyaddCustomParam(CharSequence name, CharSequence value): add custom param by passing name & value.
SsSurveysetSurveyType(@SurveyType int surveyType): set survey type to CLASSIC/CHAT/NPS
SsSurveysetThankYouRedirect(boolean thankyouRedirect): toggle redirect to thank you page outside the webview

SurveySparrow

Public constants

TypeConstant
intREPEAT_TYPE_CONSTANT: Repeat survey with a constant interval.
intREPEAT_TYPE_INCREMENTAL: Repeat survey with a incremental interval.
intSINGLE_FEEDBACK: Collect schedule feedback for once.
intMULTIPLE_FEEDBACK: Collect scheduled feedback multiple times. (Make sure that you have enabled 'Allow multiple submissions per user' for this survey)
intCLASSIC: Classic survey type
intCHAT: Chat survey type
intNPS: NPS survey type
StringSS_DEBUG_LOG: Debug log tag.

Public constructors

SurveySparrow(Activity context, SsSurvey survey) : Create SurveySparrow object with Activity context & SsSurvey

Static methods

ReturnPrototype
JSONObjecttoJSON(String text): Convert response text to JSONObject.

Public methods

ReturnPrototype
voidstartSurveyForResult(int requestCode): Start feedback activity for result.
SurveySparrowsetActivityTheme(@StyleRes int themeId): Set survey activity theme.
SurveySparrowsetAppBarTitle(CharSequence title): Set survey Activity action bar title.
SurveySparrowsetAppBarTitle(@StringRes int titleId): Set survey Activity action bar title.
SurveySparrowenableBackButton(boolean enable): Enable back button on the action bar of the survey activity.
SurveySparrowsetWaitTime(long milliseconds): How long the activity should display the thank you page.
SurveySparrowsetDialogTitle(CharSequence title): Set schedule alert dialog title.
SurveySparrowsetDialogTitle(@StringRes int titleId): Set schedule alert dialog title.
SurveySparrowsetDialogMessage(CharSequence message): Set schedule alert dialog message.
SurveySparrowsetDialogMessage(@StringRes int messageId): Set schedule alert dialog message.
SurveySparrowsetDialogPositiveButtonText(CharSequence text): Set schedule alert dialog positive button text.
SurveySparrowsetDialogPositiveButtonText(@StringRes int textId): Set schedule alert dialog positive button text.
SurveySparrowsetDialogNegativeButtonText(CharSequence text): Set schedule alert dialog negative button text.
SurveySparrowsetDialogNegativeButtonText(@StringRes int textId): Set schedule alert dialog negative button text.
SurveySparrowsetStartAfter(long milliseconds): Set the amount of time to wait before showing the scheduled dialog after launching the app for first time.
SurveySparrowsetRepeatInterval(long milliseconds): Set the amount of time to wait to show the dialog once the user declined the dialog or accepted in the case of multiple feedback enabled.
SurveySparrowsetRepeatType(@RepeatType int repeatType): Set schedule repeat type.
SurveySparrowsetFeedbackType(@FeedbackType int feedbackType): Set schedule feedback type.
SurveySparrowscheduleSurvey(final int requestCode): Schedule a take survey dialog to show after opening the activity for first time, it will show again after the repeat interval if denied, even if the user accept to take the survey you can show the dialog again by setting feedback type to MULTIPLE_FEEDBACK.
SurveySparrowclearSchedule(): Clear scheduled survey.
voidenableDebugMode(boolean enable): Enable debug mode to view useful log messages while development. (Use only while development).

OnSsResponseEventListener

Implement OnSsResponseEventListener in your Activity to listen for survey response event.

Public methods

ReturnPrototype
voidonSsResponseEvent(JSONObject data): Override this method to handle survey response event while using SsSurveyFragment.

Please submit bugs/issues through GitHub issues we will try to fix it ASAP.