SurveyBoxSdk-Android Mobile SDK - Android

Created by Surveybox.io April 28, 2024 8:10 AM

SurveyBoxSdk-Android Mobile SDK - Android

The Surveybox Mobile SDK allows you to collect feedback from your mobile app users, enabling you to trigger targeted surveys to better understand your users and collect their opinions about your products. The SDK is maintained and supported by Survicate - The Customer Experience & Survey Software.

Installation

The SDK can be installed in Android Studio using the methods described below.

Create a New Project in Android Studio

  1. 1 Launch Android Studio on your computer.
  2. 2 On the welcome screen, click on "Start a new Android Studio project." If you already have a project open, you can go to "File" > "New" > "New Project" instead.
  3. 3 In the "Create New Project" window, configure your new project by entering the application name, company domain, project location, language (Java or Kotlin), minimum SDK, form factors, orientation, and activity template.
  4. 4 Click on "Finish" to create your project.

Android Studio will start building your project and setting up the necessary files and dependencies.

Requirements

  • Using Surveybox Mobile SDK requires an account at Survaybox. Sign up for free and find your workspace key in the Access Keys tab.
  • Minimum SDK: The minimum SDK required by the SDK is set to 26 or higher.
  • Compile SDK: The SDK is compiled against SDK version 33.

Dependencies

The SDK has several dependencies listed in the dependencies block. To use the SDK, the project should include the necessary dependencies in its own Gradle file. These dependencies include:

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.6.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.6.0'

Build Features

The SDK utilizes View Binding, so the project's Gradle file should have viewBinding set to true under the buildFeatures block.

buildFeatures{
    viewBinding true
}

Installation Steps

  1. 1 Download the latest Surveybox SDK for Android and extract the zip file (approximately 194kb).
  2. 2 Open your existing Android Studio Project.
  3. 3 In the Project view, navigate to the "app" module. Expand the "app" module by clicking on the arrow next to it. Look for a folder named "libs" within the "app" module.
  4. 4 Copy the .aar file into the "libs" folder of your Android project. If the "libs" folder doesn't exist, you can create it manually in the "app" module.
  5. 5 Open your project's "build.gradle" file, located in the "app" module. It should be under the path "app/build.gradle".
  6. 6 In the "build.gradle" file, locate the "dependencies" block.
  7. 7 Add the following line inside the "dependencies" block to include the .aar file
implementation files('libs/surveybox-debug.aar')

Sync your project by clicking on the "Sync Now" button in the toolbar to ensure that the new dependency is recognized and properly added to your project.

Configuring Framework API Key

Create a class in your project and copy the below code into that class.

class MyApplication : Application() {
    lateinit var configSurvey: ConfigSurvey

    @RequiresApi(Build . VERSION_CODES . O)
    override fun onCreate() {
        super.onCreate()

        configSurvey = ConfigSurvey(applicationContext)
        configSurvey.configSurvey("Your Api Key", "Email Id")
    }

    @RequiresApi(Build . VERSION_CODES . O)
    fun checkAndShowSurvey(activity: Activity, presentClass: String) {
        val triggerClass = configSurvey.getTriggerClass()

        if (presentClass == triggerClass) {
            showSurvey(activity as AppCompatActivity)
        }
    }

    @RequiresApi(Build . VERSION_CODES . O)
    fun showSurvey(activity: AppCompatActivity) {
        val welcomeSurvey = WelcomeSurvey()
        welcomeSurvey.show(activity.supportFragmentManager, "WelcomeSurvey")
    }
}

Include the following line in your project's activity to trigger the survey automatically by matching the class name.

(application as MyApplication).checkAndShowSurvey(this, "MainActivity")

To call the survey on button click from the activity, use the following code:

(application as MyApplication).showSurvey(this)

To trigger the survey automatically by matching the class name of the fragment, use the following code:

(requireActivity().application as MyApplication).checkAndShowSurvey(requireActivity(), "Fragment class name")

To call the survey on button click from the fragment, use the following code:

(requireActivity().application as MyApplication).showSurvey(requireActivity() as AppCompatActivity)

Ready to Get Started?

Follow the installation steps above to integrate the SurveyBox SDK into your Android application and start collecting valuable user feedback today.