# Android

## 1. Install the Gradle Plugin

To install the Preventor Android SDK,  add the following to your project’s `build.gradle` file:

1. Use minSdkVersion 23 in your `build.gradle (Module:app)`
2. Add implementation `'com.preventor:preventor_sdk:2.0.73-alpha'` to your dependencies.
3. Add repository depencencies in your `build.gradle (Project Settings)`
4. In your `build.gradle (Project: app)`. Make sure you have the same version or higher `"org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"` plugin.&#x20;
5. In your `gradle.properties (Project Properties)` add this line `android.enableJetifier=true`

A complete `build.gradle`file should look similar to the example below.

```groovy
android {
    // 1. Ensure you have hat least minSdkVersion 23
    compileSdkVersion 32
    defaultConfig {
        applicationId "com.preventor.example"
        minSdkVersion 23
        targetSdkVersion 32
        versionCode 1
        versionName "1.0.0"
    }
}

dependencies {
  ... 
  // 2. Add line here  
  implementation 'com.preventor:preventor_sdk:2.0.10-alpha'
}
```

```groovy
// 3.
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://button.preventor.com/__android/v2'}
    }
```

{% hint style="success" %}
You have successfully installed the Preventor SDK!
{% endhint %}

## 2. Initialize the SDK

Initialize the SDK. See the coding example below:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
package com.preventor.example

// 1. Add import of Preventor SDK
import com.preventor.pvtidentityverification.PreventorSDK


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        // 2. Set the context to parameters "activity" and "ViewModelStoreOwner"
        val preventorSDK = PreventorSDK(this, this)
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package com.preventor.example;

// 1. Add import of Preventor SDK
import com.preventor.pvtidentityverification.PreventorSDK;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        // 2. Set the context to parameters "activity" and "ViewModelStoreOwner"
        PreventorSDK preventorSDK = new PreventorSDK(this,this);
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
You have successfully initialize the Preventor SDK!
{% endhint %}

## 3. Prefilling configs

To continue with the integration you need to set the prefill shown below. First you must obtain the config object by calling `getConfig()` method.

{% tabs %}
{% tab title="kotlin" %}

```kotlin
package com.preventor.example

import com.preventor.pvtidentityverification.PreventorSDK

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        val preventorSDK = PreventorSDK(this, this)

        // 1. GET CONFIG OBJECT 
         val config = preventorSDK.getConfig()
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package com.preventor.example;

import com.preventor.pvtidentityverification.PreventorSDK;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        PreventorSDK preventorSDK = new PreventorSDK(this,this);
        
          // 1. GET CONFIG OBJECT 
          Config config = preventorSDK.getConfig();
    }
}
```

{% endtab %}
{% endtabs %}

### Prefill Flowtype

{% hint style="danger" %}
The flow type defines the biometric process so you must select a flow type.
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
package com.preventor.example

import com.preventor.pvtidentityverification.PreventorSDK

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        preventorSDK = PreventorSDK(this, this)

                
         val config = preventorSDK.getConfig()

        // 1. SET THE FLOW TYPE
        config.flowId = "YOUR_FLOW_ID"
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package com.preventor.example;

import com.preventor.pvtidentityverification.PreventorSDK;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        PreventorSDK preventorSDK = new PreventorSDK(this,this);
         
         
         Config config = preventorSDK.getConfig();
         
          // 1. SET THE FLOW TYPE
        config.setFlowId("YOUR_FLOW_ID");
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
You must assign the flow type code. If it is blank, it will take the flow type by default.
{% endhint %}

### Prefill Credentials

{% hint style="danger" %}
You must set all credentials values ​​to correctly consume our services.
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
package com.preventor.example

import com.preventor.pvtidentityverification.PreventorSDK

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        preventorSDK = PreventorSDK(this, this)

                
         val config = preventorSDK.getConfig()

        
         config.flowId= "YOUR_FLOW_ID"
        
        // 2. SET THE CREDENTIALS    
        config.credentials.apiKey = "YOUR_API_KEY"
        config.credentials.clientSecret = "YOUR_CLIENT_SECRET"
        config.credentials.tenant = "YOUR_TENANT"
        config.credentials.banknu = "YOUR_BANKNU"
        config.credentials.env = "YOUR_ENV"
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package com.preventor.example;

import com.preventor.pvtidentityverification.PreventorSDK;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        PreventorSDK preventorSDK = new PreventorSDK(this,this);
         
         
         Config config = preventorSDK.getConfig();
         
          
        config.setFlowId("YOUR_FLOW_ID");
        
        // 2. SET THE CREDENTIALS
        config.getCredentials().setApiKey("YOUR_API_KEY");
        config.getCredentials().setClientSecret("YOUR_CLIENT_SECRET");
        config.getCredentials().setTenant("YOUR_TENANT");
        config.getCredentials().setBanknu("YOUR_BANKNU");
        config.getCredentials().setEnv("YOUR_ENV");
    }
}
```

{% endtab %}
{% endtabs %}

| Value                | Description                 |
| -------------------- | --------------------------- |
| YOUR\_API\_KEY       | your provided apikey.       |
| YOUR\_CLIENT\_SECRET | your provided clientsecret. |
| YOUR\_TENANT         | your provided tenant.       |
| YOUR\_BANKNU         | your provided banknu.       |
| YOUR\_ENV            | your provided env.          |

### Prefill Cif Code

The Cifcode is the unique customer profile code.&#x20;

&#x20;

{% hint style="info" %}
If the Cifcode is empty, a unique code is assigned.
{% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
package com.preventor.example

import com.preventor.pvtidentityverification.PreventorSDK

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        preventorSDK = PreventorSDK(this, this)

                
         val config = preventorSDK.getConfig()

        
        config.flowId= "YOUR_FLOW_ID"
           
        config.credentials.apiKey = "YOUR_API_KEY"
        config.credentials.clientSecret = "YOUR_CLIENT_SECRET"
        config.credentials.tenant = "YOUR_TENANT"
        config.credentials.banknu = "YOUR_BANKNU"
        config.credentials.env = "YOUR_ENV"
        
        // 3. SET THE CIF CODE
        config.currentUserInfo.cifCode = "YOUR_CIFCODE"
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package com.preventor.example;

import com.preventor.pvtidentityverification.PreventorSDK;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        PreventorSDK preventorSDK = new PreventorSDK(this,this);
         
         
         Config config = preventorSDK.getConfig();
         
          
        config.setFlowId("YOUR_FLOW_ID");

        config.getCredentials().setApiKey("YOUR_API_KEY");
        config.getCredentials().setClientSecret("YOUR_CLIENT_SECRET");
        config.getCredentials().setTenant("YOUR_TENANT");
        config.getCredentials().setBanknu("YOUR_BANKNU");
        config.getCredentials().setEnv("YOUR_ENV");
        
        // 3. SET THE CIF CODE
        config.getCurrentUserInfo().setCifCode("YOUR_CIFCODE");
    }
}
```

{% endtab %}
{% endtabs %}

### Prefill Title App Bar

Define an app title that indicates the process to be performed.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
preventorSDK.setTitleAppBar("YOUR_TITLE_APP_BAR")
```

{% endtab %}

{% tab title="Java" %}

```java
preventorSDK.setTitleAppBar("YOUR_TITLE_APP_BAR")
```

{% endtab %}
{% endtabs %}

## 4. Start the Verification

To start a new verification, you first need to create the preventor verification button.

### Add Button in your XML

```xml
 <com.preventor.pvtidentityverification.widgets.PreventorButton
        android:id="@+id/identityVerificationButton"
        android:layout_width="161dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
```

### Start Verification

To start a verification, prepare the following:

1. Add the reference to verification button.
2. Call `initialize()` method to start the preventorSDK.
3. Call `validateApiKey()` method to start the verification.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
// 1. Add verification button reference.

val identityVerificationButton = findViewById<PreventorButton>(R.id.identityVerificationButton)

// 2. Call initialize() method.
preventorSDK.initialize()

// 3. Call validateApiKey() method.
identityVerificationButton.setOnClickListener {
    preventorSDK.validateApiKey()
}
```

{% endtab %}

{% tab title="Java" %}

```java
// 1. Add verification button reference.
PreventorButton identityVerificationButton = findViewById(R.id.identityVerificationButton);

// 2. Call initialize() method.
preventorSDK.initialize();

// 3. Call validateApiKey() method.
identityVerificationButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        preventorSDK.validateApiKey();
    }
});
```

{% endtab %}
{% endtabs %}

To start verification you can also use this call `validateApiKey()` anywhere in your code when all necessary resources have already been completed.

## 5. Handling Verifications

To find out if a user has completed the verification process, canceled it or there was an error. To do this, you can implement the following delegate / callback methods:

| Method        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onStart`     | This callback method is triggered once a user starts the verification flow.                                                                                                                                                                                                                                                                                                                                                                        |
| `onSubmitted` | Method that is being called once verification data is submitted to Preventor.                                                                                                                                                                                                                                                                                                                                                                      |
| `onFinish`    | Method that is being called once a user clicks the "Finish" button.                                                                                                                                                                                                                                                                                                                                                                                |
| `onError`     | <p>This callback method fires when a user canceled the verification flow, the verification ended with an error, or the user performed an incorrect process. You can use this to find out the reason for the error.</p><p>Error codes: </p><p><code>CANCELLED\_BY\_USER</code></p><p><code>BIOMETRIC\_AUTHENTICATION\_FAILED</code></p><p><code>BAD\_STEP\_BY\_USER</code> </p><p><code>MISSING\_PARAMETERS</code></p><p><code>TIME\_OUT</code></p> |
| `onNextStep`  | This callback indicates that it is possible to proceed to the next verification                                                                                                                                                                                                                                                                                                                                                                    |
| `onComplete`  | This callback indicates that all necessary resources have already been completed                                                                                                                                                                                                                                                                                                                                                                   |

Should look similar to the example below.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
preventorSDK.callback(object : PreventorSDKListener {
            override fun onStart() {
                println("MainActivity onStart");
            }

            override fun onFinish(ticked: Ticked) {
                println("MainActivity onFinish");
            }

            override fun onError(error: String) {
                println("MainActivity onError: $error");
            }

            override fun onSubmitted(ticked: Ticked) {
                println("MainActivity onSubmitted");
            }
            override fun onNextStep() {
            println("MainActivity onNextStep");
            }
            
            override fun onComplete() {
            println("MainActivity onComplete");
            }

        })
```

{% endtab %}

{% tab title="Java" %}

```java
preventorSDK.callback(new PreventorSDKListener() {
            @Override
            public void onStart() {
                System.out.println("MainActivity onStart");
            }

            @Override
            public void onFinish(Ticked ticked) {
                System.out.println("MainActivity onFinish");
            }

            @Override
            public void onError(@NonNull String error) {
                System.out.println("MainActivity onError: " + error);
            }

            @Override
            public void onSubmitted(Ticked ticked) {
                System.out.println("MainActivity onSubmitted");
            }
            
            @Override
            public void onNextStep(Ticked ticked) {
                System.out.println("MainActivity onNextStep");
            }
            
            @Override
            public void onComplete(Ticked ticked) {
                System.out.println("MainActivity onComplete");
            }
        });
```

{% endtab %}
{% endtabs %}

When the verification is finished it will return a ticked object in which you can see the results of the verification. Within them take as reference cifcode, ticketId, flowStatus, dispositionStatus.

| Result            | Value                                                                                                                                                          |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| cifcode           | The cifcode is the unique customer profile code.                                                                                                               |
| ticketId          | The ticketId is the unique code of the verification.                                                                                                           |
| flowStatus        | <p>Indicates the general status of the ticket.</p><p>See the following codes:</p><p>ACCEPTED, IN\_PROGRESS, REJECTED, ABANDONED.</p>                           |
| dispositionStatus | <p>Indicates the current disposition of the ticket.</p><p>See the following codes:</p><p>PASSED, NEED\_REVIEW, RETRY, FAILED, PROCESSING, LOST\_CONECCTION</p> |

When the ticket ends in the following combinations, flowStatus and dispositionStatus respectively:

| Status                       | Description                                                                               |
| ---------------------------- | ----------------------------------------------------------------------------------------- |
| ACCEPTED - PASSED            | Verification completed successfully.                                                      |
| IN\_PROGRESS - NEED\_REVIEW  | Verification is complete but there is information to review.                              |
| IN\_PROGRESS - RETRY         | Verification did not complete and requires retry.                                         |
| IN\_PROGRESS -  PASSED       | One step of verification has been completed and you can move on to the next.              |
| REJECTED - FAILED            | Verification has been refused due to negative results.                                    |
| ABANDONED - LOST\_CONECCTION | The verification has failed due to some unhandled error and the connection has been lost. |
| ABANDONED - TIME\_OUT        | Verification failed due to user inactivity.                                               |

## 6. Example project

See the example project below:&#x20;

<https://github.com/preventorid/button-android-sdk-app/tree/main>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.preventor.com/mobile-client-side-sdks/android.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
