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.

  5. In your gradle.properties (Project Properties) add this line android.enableJetifier=true

A complete build.gradlefile should look similar to the example below.

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'
}
// 3.
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://button.preventor.com/__android/v2'}
    }

You have successfully installed the Preventor SDK!

2. Initialize the SDK

Initialize the SDK. See the coding example below:

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)
    }
}

You have successfully initialize the Preventor SDK!

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.

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()
    }
}

Prefill Flowtype

The flow type defines the biometric process so you must select a flow type.

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"
    }
}

You must assign the flow type code. If it is blank, it will take the flow type by default.

Prefill Credentials

You must set all credentials values ​​to correctly consume our services.

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"
    }
}

Prefill Cif Code

The Cifcode is the unique customer profile code.

If the Cifcode is empty, a unique code is assigned.

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"
    }
}

Prefill Title App Bar

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

preventorSDK.setTitleAppBar("YOUR_TITLE_APP_BAR")

4. Start the Verification

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

Add Button in your 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.

// 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()
}

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:

Should look similar to the example below.

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");
            }

        })

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.

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

6. Example project

See the example project below:

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

Last updated