# Android SDK

## How It Works?

1. Register your app at <https://www.verifykit.com> and get your client keys and server key.
2. Add VerifyKit SDK to your app
3. Configure and start VerifyKit SDK
4. When verification is complete, send **sessionId** which VerifyKit SDK gives you to your backend service.
5. At your server side, get user's phone number from VerifyKit service with **serverKey** and **sessionId**. You can check [Rest Api Docs](https://app.gitbook.com/o/-MNYXEHRQyQE-fDwM2pr/s/MSJXU5NMdqE206LMn3AL/~/changes/dzIMOEIPZqCe1xjSsjYj/start-to-verify/rest-api).

{% hint style="danger" %}

## **IMPORTANT NOTE**

**ServerKey** is used for getting info from VerifyKit service.

Please keep **ServerKey** safe. Do not include it in your client's code base.
{% endhint %}

## VerifyKit Flow <a href="#security" id="security"></a>

<figure><img src="/files/fL7PtTziBe1LPupiyXVO" alt=""><figcaption></figcaption></figure>

## Installation

### Requirements

Minimum SDK Version is api 16

{% code title="Java" %}

```java
// Add it to your app build.gradle at the end of repositories:
implementation 'org.bitbucket.verifykit:verifykit-android:0.11.1'
//Add it to your root build.gradle at the end of repositories:
allprojects {
  repositories {
      ...    
      maven { url 'https://jitpack.io' }  
  }
}
```

{% endcode %}

## Usage <a href="#usage" id="usage"></a>

In your Application file you should initialize VerifyKit. **VerifyKit.init()** method needs VerifyKitOptions object.

#### Usage

{% code title="Application.kt" %}

```
  val theme = VerifyKitTheme(
            backgroundColor = Color.WHITE
        )
        VerifyKit.init(
            this,
            VerifyKitOptions(
                isLogEnabled = true,
                verifyKitTheme = theme
            )
        )
```

{% endcode %}

You can call VerifyKit.startVerification(this) method from your Activity or Fragment then get the result via VerifyCompleteListener interface from your Activity or Fragment.

#### VerifyCompleteListener

{% code title="Kotlin" %}

```kotlin
VerifyKit.startVerification(this, object : VerifyCompleteListener {
    override fun onSuccess(sessionId: String) {
      // TODO operate SUCCESS process    
    }    
    override fun onFail(error: VerifyKitError) {
      // TODO operate FAIL process    
    }
})
```

{% endcode %}

**Optional:** You can pass user phone number to VerifyKit with `startVerification` method. In this way VerifyKit doesn’t ask phone number to user

{% code title="Kotlin" %}

```kotlin
 VerifyKit.startVerification(  
    activity = this,  
    countryPhoneCode = "+90",
    phoneNumber = "5555555555",  
    mCompleteListener = object : VerifyCompleteListener {  
        override fun onSuccess(sessionId: String) {  
            // TODO operate SUCCESS process  
	  }  
  
        override fun onFail(error: VerifyKitError) {  
            // TODO operate FAIL process  
	  }  
    })
```

{% endcode %}

#### VerifyKit.checkInterruptedSession

There may be a case when user chooses a third party messaging app for validation, sends a message, but doesn't return to main app and kills it. In that case, that user is verified with VerifyKit but the main app doesn't know it yet.

To fix this, we have a method to check interrupted session status.

{% code title="Application.kt" %}

```kotlin
VerifyKit.checkInterruptedSession(object : VerifyCompleteListener {
    override fun onSuccess(sessionId: String) {
        // sessionId    
    }    
    override fun onFail(error: VerifyKitError) {
        // error    
    }
})
```

{% endcode %}

### AndroidManifest <a href="#androidmanifest" id="androidmanifest"></a>

Open the /app/manifest/AndroidManifest.xml file.

Add the following meta-data elements, an activity for VerifyKit and intent filter for App Link inside your application element:

```
<meta-data
    android:name="com.verifykit.sdk.clientKey"    
    android:value="your_verifykit_client_key" />
<meta-data
    android:name="com.verifykit.sdk.clientSecret"    
    android:value="your_verifykit_client_secret" />
<activity
    android:name="com.verifykit.sdk.ui.VerificationActivity"    
    android:launchMode="singleInstance"    
    android:screenOrientation="portrait">  
<intent-filter android:autoVerify="true">
      <action android:name="android.intent.action.VIEW" />      
      <category android:name="android.intent.category.DEFAULT" />      
      <category android:name="android.intent.category.BROWSABLE" />      
      <data
            android:host="your_deep_link_url"          
            android:pathPattern="your_deep_link_pattern"          
            android:scheme="https" />    
      </intent-filter>
</activity>
```

An Android App Link is a deep link based on your website URL that has been verified to belong to your website. So clicking one of these immediately opens your app if it's installed—the disambiguation dialog does not appear. Though the user may later change their preference for handling these links. For verifying your App Link see [document](https://developer.android.com/training/app-links/verify-site-associations).

### ProGuard <a href="#proguard" id="proguard"></a>

`-keep class com.verifykit.sdk.core** { *; }`

### &#x20;Backend Integration

When the verification is complete, in order to get information of the verified user, you should integrate with VerifyKit Rest API. After receiving the sessionID variable from the Web SDK, you can fetch your client's data, such as phone numbers , from VerifyKit Rest API service.

This integration requires a **ServerKey** token that is unique to your application in VerifyKit and used as both an identifier and a security measure. For this reason, you have to use your **ServerKey** token in backend integration. You can not use **ServerKey** on your client-side.

For further info on how to integrate this part please click [here.](/start-to-verify/rest-api.md#last-step-complete-validation)

<figure><img src="/files/5q6QF3wUIrXil0bD3pdS" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Need some help?**

We all need a little help sometimes. If you have any question or request, feel free to [**create an issue**](https://github.com/verifykit/verifykit-sdk-android/issues).
{% endhint %}


---

# 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.verifykit.com/start-to-verify/android-sdk.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.
