Android

This is a walkthrough of how you can integrate the Onboarding or Authenticate SDK for Android applications.

Getting started

In order to perform an Onboarding or an Authenticate, you should follow those steps:

  1. Set up the SDK: install and import the SDK.

  2. Get a token: request a token using your business credentials.

  3. Get the user workflow result from SDK: use the Message handler to get insights about the user workflow.

  4. Get the Analysis result: use your callback or the endpoint to get the analysis result.

1. Set up the SDK

1.1 Project requirements

The SDK supports API level 24 and above (distribution stats).

Our configuration is currently set to the following:

  • minSdkVersion = 24

  • targetSdkVersion = 34

  • android.useAndroidX=true

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }  

For Kotlin

  kotlinOptions {
    jvmTarget = "11"
  }

1.2 Proguard Rules

-keep class * extends androidx.lifecycle.ViewModel {
    public *;
    }

-keep class * extends androidx.lifecycle.AndroidViewModel {
    public *;
}

1.3 Add repository

Add the repository URL to the project-level build.gradle:

allprojects {
    repositories {
        google()
        mavenCentral()

        maven {
            url "https://repository.shareid.net/repository/mvn-hosted/"
            credentials {
                username = 'your-repository-username'
                password = 'your-repository-password'
            }
        }
    }
}

1.4 Add library dependency

Add the library dependency to the app module’s build.gradle:

dependencies {
    implementation 'ai.shareid:sdk:x.y.z' //use the latest version
    implementation 'com.airbnb.android:lottie:6.4.0'
}

1.5 Sync the Project

After you’ve added the repository and dependency, sync the Gradle project by clicking on the “Sync Now” notification in Android Studio or manually triggering a sync via File > Sync Project with Gradle Files.

2. Get a token

Use the credentials you recieved from ShareID's team to get an authentcation token and launch an onboarding or authenticate workflow.

Depending on the SDK you are integrating (Onboarding/Authenticate), you may use an API here Get a Token

3. Start an onboarding or authenticate flow

Use your token to start ShareIdMainActivity and action ShareIdMainActivity.SHARE_ID_METHOD

Use the value ShareIdMainActivity.SHARE_ID_ONBOARDING for Onboarding and ShareIdMainActivity.SHARE_ID_AUTHENTICATE for Authenticaticate.

private ActivityResultLauncher activityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
        onActivityResult(1, result);
    });

    .....
    Intent intent = new Intent(getBaseContext(), ShareIdMainActivity.class);
    //For Onboarding
    intent.putExtra(ShareIdMainActivity.SHARE_ID_METHOD,ShareIdMainActivity.SHARE_ID_ONBOARDING);
    //For Authenticate
    intent.putExtra(ShareIdMainActivity.SHARE_ID_METHOD,ShareIdMainActivity.SHARE_ID_AUTHENTICATE);
    intent.putExtra(ShareIdMainActivity.SHARE_ID_SERVER_URL, "the base url");
    intent.putExtra(ShareIdMainActivity.SHARE_ID_SERVICE_TOKEN, "your token");
    intent.putExtra(ShareIdMainActivity.SHARE_ID_APPLICANT_ID, "applicant Id is required")
    activityResultLauncher.launch(intent);       

Below a Kotlin example:

val activityResultLauncher = registerForActivityResult(
    ActivityResultContracts.StartActivityForResult()
) { result ->
    if (result.resultCode == Activity.RESULT_OK) {
        val data: Intent? = result.data
    }
}

    .....
    val intent = Intent(this, ShareIdMainActivity::class.java)
// For Onboarding
intent.putExtra(ShareIdMainActivity.SHARE_ID_METHOD, ShareIdMainActivity.SHARE_ID_ONBOARDING)
// For Authenticate
intent.putExtra(ShareIdMainActivity.SHARE_ID_METHOD, ShareIdMainActivity.SHARE_ID_AUTHENTICATE)

intent.putExtra(ShareIdMainActivity.SHARE_ID_SERVER_URL, "the base url")
intent.putExtra(ShareIdMainActivity.SHARE_ID_SERVICE_TOKEN, "your token")
intent.putExtra(ShareIdMainActivity.SHARE_ID_APPLICANT_ID, "applicant Id is required")

// Launch the activity and wait for result
activityResultLauncher.launch(intent)     

The table below describes the list of parameters:

Parameter
Format
Comment

SHARE_ID_SERVER_URL

string

optional The server url (sandbox or prod)

SHARE_ID_SERVICE_TOKEN

string

required Your access token

SHARE_ID_APPLICANT_ID

string

required if Authenticate The applicant id received after completing the onboarding process.

4. Get the user workflow result from SDK

In order to retrieve ShareID results from the flow, customize the method onActivityResult on your activity/fragment. You will also need to implement the interface ShareIdResultListener:

private void onActivityResult(int requestCode, ActivityResult result) {
if (requestCode == 1)
ShareId.getInstance().messageHandler(result, new MessageHandler() {
    @Override
    public void success(ShareIdResult shareIdResult) {
    Toast.makeText(getApplicationContext(), shareIdResult.getMessage(), Toast.LENGTH_LONG).show();
    }

    @Override
    public void exit(ShareIdResult shareIdResult) {
    Toast.makeText(getApplicationContext(), shareIdResult.getMessage(), Toast.LENGTH_LONG).show();
    }

    @Override
    public void failure(ShareIdResult shareIdResult) {
    Toast.makeText(getApplicationContext(), shareIdResult.getMessage(), Toast.LENGTH_LONG).show();
    }
});
} 

When the user will successfully complete the flow and the captured videos will be uploaded, the success method will be invoked. The ShareIdResult contain the error description and does not contain any information about the document nor the user captured during the acquisition phase.

To view all possible end-of-process results in our SDK, please refer to the Message Handler for all success, exit and failure states.

5. Get the Analysis result

When the processing of an onboarding request is finished, you may receive the result through the callback if you provided it. You may also, fetch yourself the result by calling our API.

See Get the analysis result for more details.

Customisation

ShareID's Android SDK has been designed to enable customization during integration.

Text content

To change the text content, add a values-XX file to your application and use the same keys as ShareID so that they are overwritten by your text.

Languages supported:

  • 🇸🇦 (ar), 🇩🇪 (de), 🇬🇧 (en), 🇪🇸 (es), 🇫🇷 (fr), 🇮🇹 (it), 🇵🇹 (pt), 🇷🇴 (ro), 🇷🇺 (ru)

[!info] Important

Be sure to add values-XX to your res folder with all the languages you want to support in your application. (This enables RTL navigation)

XX means the language code. Ex: ar or en or fr ...

Technical support and contact 💬

Last updated