# Usage

## Minimum Requirements

1. API Level for use is 21 (Android 5.0)
2. Java 7
3. Access to storage and camera
4. AndroidX

## Installation

Add the following lines of code to your project-level gradle to your repositories

```kotlin
maven {
      credentials {
         username “sdk”
         password “sdk123456”
      }
      url “http://www.valifystage.com/artifactory/libs-release/”
}

maven {
      url "http://jitpack.io"
}

```

Add the following lines of code to your app-level gradle to your dependencies&#x20;

```kotlin
implementation 'com.valify:ValifyEKYC:$LATEST_VERSION’
```

{% hint style="info" %}
Latest version [version-2.2.2](https://valify.gitbook.io/ios-sdk-documentation/android/version-2.2.0/changelog/version-2.2.2 "mention")
{% endhint %}

## Authentication

In order to generate an access token that will be used in the SDK authentication settings, use our [authentication service API](https://valify.gitbook.io/documentation/general/oauth-token).

## Configuration

Declare the following Valify variables

```kotlin
private Valify valify;
private ValifyConfig.Builder valifyConfig;
```

Initialize your SDK in your activity or fragment as follows:

```kotlin
valify = new ValifyFactory(getApplicationContext()).getClient(); // Pass context
valifyConfig = new ValifyConfig.Builder();
```

Configure your SDK settings:

```kotlin
// required settings
valifyConfig.setBaseUrl("Base Url");
.setAccessToken ("Access Token");
.setBundleKey("Bundle Key");

// optional settings
.withOCR(Boolean ocr);
.withDocumentVerification(Boolean document_verification);
.withWatermark(Boolean watermark);
.withLiveness(Boolean liveness);
.withFaceMatch(Boolean face_match);
.withRating(Boolean rating);
.withTerms(Boolean terms);
.withTutorial(Boolean tutorial);
.withDataUpdating(Boolean data_updating);
.withoutPreviewData();      // use when you do not want to preview data
```

If you don’t specify any services, the following services will be set by default to “True” and the user will go through the complete eKYC process:

```
// default settings

.withOCR(Boolean ocr);
.withLiveness(Boolean liveness);
.withFaceMatch(Boolean face_match);
.withRating(Boolean rating);
.withTerms(Boolean terms);
.withTutorial(Boolean tutorial);
.withDataUpdating(Boolean data_updating);
```

If you use the Face Match service after the OCR or OCR w/ Verification service then the face in the front side image of the national ID captured during the OCR or OCR w/ Verification step will be used for comparison with the image captured during the Face Match step.

If you use the Face Match service separately, you need to either pass an image or a transactions id for a hit previously made to our OCR or OCR w/ Verification service for comparison with the image that will be captured for the user going through the SDK experience:

```kotlin
.withCustomFaceMatchImage(byte[] image);
.withCustomFaceMatchTransactionId(String frontTransactionId);
```

Depending on the image size, compress as follows:

```kotlin
imageBitmap = Bitmap.createScaledBitmap(
      bitmap, 
      (int)(imageBitmap.getWidth() * 0.8), 
      (int) (imageBitmap.getHeight() * 0.8),
      true);

// uncomment for images larger than 500 KB
// bitmap.compress(Bitmap.CompressFormat.JPEG, 10, stream);

// uncomment for images smaller than or equal to 500 KB 
// bitmap.compress(Bitmap.CompressFormat.JPEG, 70, stream);
```

The default language of the SDK is English, to set it to Arabic add the following:

```kotlin
.setLanguage("ar");
```

To add your custom logo to the splash screen:

{% tabs %}
{% tab title="version 2.1.0" %}

```
.withCustomizedLogo("int logoImageId");
```

{% endtab %}

{% tab title="version 2.0.0" %}

```
.withCustomizedLogo("byte[] logo");
```

{% endtab %}
{% endtabs %}

Specify the number of instructions, length of each instruction, and the number of maximum number of trials for the liveness service as follows:

```kotlin
// default value is 4, range of allowed values is [1, 10]
.seLivenessNumOfInstruction(int livenessNumOfInstruction);

// default value is 10 seconds, minimum value is 5 seconds
.setLivenssTimerSeconds(int livenssTimerSeconds);

// minimum value is 1
.setLivenessNumOfTrials(int livenessNumOfTrials);
```

Remove the actions you do not want the user to perform for the liveness service as follows:

```kotlin
.withoutSmile();
.withoutCloseEyes();
.withoutLookLeft();
.withoutLookRight();
```

Start the Valify Service:

```kotlin
try {
      valify.startActivityForResult(MainActivity.this,1,
      valifyConfig.build());
} catch(ValifyException e) {
      e.printStackTrace();
}
```

Your activity should implement `onActivityResult` in order to receive the data collected from the process similar to the following example:

```kotlin
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      valify.handleActivityResult(resultCode, data, new     
            Valify.ValifyResultListener()
            {
                  @Override
                  public void onSuccess(
                        String valifyToken,ValifyData valifyData) {}

                  @Override
                  public void onExit(
                        String valifyToken,String step, 
                        ValifyData valifyData) {}

                  @Override
                  public void onError(
                        String valifyToken,int errorCode, 
                        String step, ValifyData valifyData) {}
            });
}
```

In this callback, we call the method `handleActivityResult` from the Valify object which overrides onSuccess, onExit & onError:

1. **OnSuccess** is only called when the user has completed the experience successfully. The Valify token (`valifyToken`), and the data collected ([`valifyData`](https://valify.gitbook.io/ios-sdk-documentation/android/version-2.2.0/valifydata-object)) are returned.
2. **OnExit** is only called when the user exits the SDK voluntarily returning to the main app. The Valify token (`valifyToken`), step at which the user exited (`step`), and the data collected before exiting ([`valifyData`](https://valify.gitbook.io/ios-sdk-documentation/android/version-2.2.0/valifydata-object)) are returned to the app.
3. **OnError** is only called when the user aborts as a result of an error. The Valify token (`valifyToken`), error code ([`errorCode`](https://valify.gitbook.io/ios-sdk-documentation/error-codes)), step at which the user exited (step), and the data collected before the error occurred ([`valifyData`](https://valify.gitbook.io/ios-sdk-documentation/android/version-2.2.0/valifydata-object)) are returned to the app.
