Android SDK - Quick Start

Please note: This guide focuses on using the industry standard of including libraries remotely using Gradle. If you use other methods, please see the following links:

To add the SDK locally using Gradle
To add the SDK remotely using Maven

To add the SDK remotely using Gradle:

  1. Add the following code to your build.gradle file(s):
    allprojects {
        repositories {
            jcenter()
        } 
    }
    
    dependencies {
        compile 'com.foresee.sdk:sdk:4.1'
    }
    
  2. Proceed to Instrumenting your code below

Instrumenting your code:

  1. If the application does not have a custom Application class, i.e., a class that extends android.app.Application, create one. Ensure that the AndroidManifest.xml file is updated appropriately.
  2. Add the foresee_configuration.json file to the res/raw directory (if there is no directory called raw in the resources directory, create that directory). Separate configurations can be specified on a per-locale basis by using the resource folder suffixes, eg res/raw-fr, but make sure you include a default res/raw folder as per Android requirements.
  3. Within the onCreate method of the custom Application class, initialize the ForeSee SDK by invoking ForeSee.start(this). For example, the onCreate() method might look something like the following:
    @Override
    public void onCreate() {
      super.onCreate();
      ForeSee.start(this);
    }
  4. If you are not using Replay, please skip to step 5. If you are using Replay, override onCreateView() in each of your Fragments, and ensure that the fragment is registered with the SDK by calling ForeSee.registerFragmentView(yourFragmentView); in the Fragment’s onCreateView() method. For example, a typical onCreateView() method might look like the following:
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
     // Inflate the layout for this fragment
     View rootView = inflater.inflate(R.layout.fragment_holidays, container, false);
    
     // .. Your code ..
    
     // Register the fragment's view
     ForeSee.registerFragmentView(rootView);
     return rootView;
    }
    
  5. At the point the survey is to be displayed, invoke ForeSee.checkIfEligibleForSurvey() to perform a survey eligibility check.This is usually done on application start and would therefore be placed in the ”entry point” Activity (typically this would be the Activity with the intent filter action of android.intent.action.MAIN and intent filter category of android.intent.category.LAUNCHER).For example, this might be implemented in the onResume() method as follows:
    @Override 
    public void onResume() {
      super.onResume();
      ForeSee.checkIfEligibleForSurvey();
    }
    

To add the SDK locally using Gradle:

  1. Add foresee-sdk-android-4.1.aar to the project libs directory.
  2. Add the following lines to your build.gradle file(s):
    allprojects {
        repositories {
            flatDir{
                dirs 'libs'
            }
        }
    }
    
    dependencies {
        compile (name:'foresee-sdk-android-4.1', ext:'aar')
        compile 'com.google.code.gson:gson:2.2.4'
    }
    
  3. Proceed to Instrumenting your code below

To add the SDK remotely using Maven:

  1. Add the following to your settings.xml file:
  2. <profiles>
        <profile>
            <repositories>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>bintray-foreseemobile-Android</id>
                    <name>bintray</name>
                    <url>http://foreseemobile.bintray.com/Android</url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>bintray-foreseemobile-Android</id>
                    <name>bintray-plugins</name>
                    <url>http://foreseemobile.bintray.com/Android</url>
                </pluginRepository>
            </pluginRepositories>
            <id>bintray</id>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>bintray</activeProfile>
    </activeProfiles>
    
    <dependencies>
      <dependency>
        <groupId>com.foresee.sdk</groupId>
        <artifactId>sdk</artifactId>
        <version>4.1</version>
        <type>pom</type>
        </dependency>
    <dependencies>
    
  3. Proceed to Instrumenting your code below

Other articles in this section:

  1. SDK Overview
  2. Quick Start (current article)
  3. Configuration
  4. Trigger
  5. Replay
  6. Proguard
  7. Frequently Asked Questions
  8. Troubleshooting