VK Cloud logo

Connecting to a mobile application on Android

  1. Download VK Капча SDK:

    1. Add the Maven repository to dependencyResolutionManagement or settings.gradle.kts:

      dependencyResolutionManagement {    repositories {        maven(url = "https://artifactory-external.vkpartner.ru/artifactory/vkid-sdk-android/")    }}
    2. Add the library to your application module's build.gradle.kts:

      dependencies {    implementation("com.vk.id.captcha:vkid-captcha:<VERSION>")}

      Here <VERSION> is the VK Капча SDK version for Android (0.0.13).

    3. In your application's Android Manifest, override the authority of the provider that initializes the SDK:

      <application>    <provider        android:name="com.vk.id.captcha.init.SdkInitContentProvider"        android:authorities="your.unique.authority"        android:exported="false"        tools:replace="authorities" /></application>
  2. Get a link from the backend to launch the captcha widget.

  3. (Optional) Configure the captcha localization language. Use the SDK method VKCaptcha.setLocale().

  4. Display the captcha to the user. Use the SDK method VKCaptcha.openCaptcha().

  5. Handle the captcha completion result using the interface VKCaptchaResultListener:

    • If a successful captcha completion token is returned, send it to the backend for validation.

    • If the user closed the captcha, nothing is sent to the backend. Determine what will happen in the frontend in this case.

Kotlin code example:

import com.vk.id.captcha.api.VKCaptchaimport com.vk.id.captcha.api.listener.VKCaptchaResultListenerimport com.vk.id.captcha.api.data.VKCaptchaResultimport android.net.Uriclass CaptchaHandler {    fun handleCaptcha(captchaUrl: String) {        val listener = object : VKCaptchaResultListener {            override fun onResult(result: VKCaptchaResult) {                when (result) {                    is VKCaptchaResult.Success -> {                        val token = result.token                        repeatRequest(token)                    }                    is VKCaptchaResult.Error -> {                        // Error handling or captcha closure                    }                }            }        }        val uri = Uri.parse(captchaUrl)        val domain = "${uri.scheme}://${uri.host}"        VKCaptcha.openCaptcha(            domain = domain,            redirectUri = captchaUrl,            listener = listener        )    }    private fun repeatRequest(token: String) {        // Repeat request with token    }}