Android SDK Initial Integration Guide

Use this guide to integrate the FaceTec Android SDK into Your App.

For integrating the FaceTec iOS SDK into Your App, see the iOS SDK Initial Integration Guide.

For integrating the FaceTec Browser SDK into Your App, see the Browser SDK Initial Integration Guide.

Video Guide

Prerequisite

Download Android Studio.

Create a New App in Android Studio:

  1. Open Android Studio. Go to File → New Project → Empty Views Activity. Choose a name for Your App's project, select Java as the Language, and select Groovy DSL (build.gradle) as the Build Configuration Language.

Add the FaceTec Android SDK to Your New App:

  1. Download and extract the FaceTec Android SDK. Copy facetec-sdk-#####.aar from the FaceTec Android SDK to the root of Your App's folder.
  2. Open build.gradle (Module) in both the Sample App and Your App. Copy these two implementations from the Sample App to Your App:
    implementation 'com.squareup.okhttp3:okhttp:<VERSION_NUMBER>'
    implementation 'com.facetec:facetec-sdk:<FACETEC_SDK_VERSION>@aar'
  3. In Your App, open settings.gradle and add facetec-sdk-#####.aar as a dependency.
    1. Add flatDir{ dirs '.' } to dependencyResolutionManagement{repositories{ }}.
    2. Click sync now.
  4. On success, Your App will build with no errors.

Import the Default FaceTec Wrapper Classes & Methods:

  1. Open the Sample App in a separate window of Android Studio. Copy the following files from the Sample App’s com.facetec.sampleapp directory into Your App's Main Directory (i.e. the one with MainActivity):
    • Config.java
    • SessionRequestProcessor.java
    • SampleAppNetworkingRequest.java
    • SampleAppNetworkingLibExample.java
  2. In MainActivity.java, import the FaceTec SDK, the FaceTec SDK Configuration Files and Helper Classes, and the Android Widget Button.
    import com.facetec.sdk.FaceTecInitializationError;
    import com.facetec.sdk.FaceTecSDK;
    import com.facetec.sdk.FaceTecSDKInstance;
    import android.widget.Button;
  3. in MainActivity.java, add a public field for the FaceTecSDK Instance in the Main Activity Class.
    public FaceTecSDKInstance sdkInstance;
  4. In MainActivity.java, add the following code to the onCreate() Method to preload and initialize the FaceTec SDK:
    // Optional - Preload resources related to the FaceTec SDK so that it can run as soon as possible.
    // Run this as soon as you think you might use the SDK for optimal start up performance.
    FaceTecSDK.preload(this);
    
    FaceTecSDK.initializeWithSessionRequest(this, Config.DeviceKeyIdentifier, new SessionRequestProcessor(), new FaceTecSDK.FaceTecInitializeCallback(){
      @Override
      public void onSuccess(@NonNull FaceTecSDKInstance sdkInstance) {
        MainActivity.this.sdkInstance = sdkInstance;
        
        // Handle Successful Initialization of the FaceTec SDK with Your Custom Logic.
        ...
      }
    
      @Override
      public void onError(@NonNull FaceTecInitializationError error) {
    
        // Handle the Initialization Error with Your Custom Logic.
        ...
      }
    });
  5. In the recently imported files, delete all lines referencing the FaceTec Sample App's Bundle ID (i.e. com.facetec.sampleapp), Utilities, and SampleAppOfficialIDPhotoFragment. These will be thrown as errors when building.
  6. In SampleAppNetworkingRequest.java, remove all references to demonstrationExternalDatabaseRefID.
  7. In SampleAppNetworkingRequest.java, remove the storeOfficialIDPhotoIfApplicable() Method and all references to it.
  8. In MainActivity.java, update onActivityResult() to the following:
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
    
      // Handle the FaceTec Session Result with Your Custom Logic.
      ...
    }
  9. On success, Your App will build with no errors.

Create Button for 3D Liveness Checks:

  1. Open res/layout/activity_main.xml and add a button named LivenessCheck to the center of the screen.
  2. In MainActivity.java, configure the Liveness Check Button by adding the following code to the onCreate() Method:
    Button livenessCheck = findViewById(R.id.LivenessCheck);
    livenessCheck.setOnClickListener(v -> {
      sdkInstance.start3DLiveness(this, new SessionRequestProcessor());
    });
    
  3. On success, Your App will be able to build and run!
Important Note: Your Application needs to wait for the FaceTec SDK to initialize before performing a 3D Liveness Check.