VK Cloud logo

Connecting to a mobile application on Android

  1. Download the 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. Connect the library in the app module's build.gradle.kts:

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

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

    3. In your app'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 the link for launching the captcha widget from the backend.

  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 VKCaptchaResultListener interface:

    • 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.

Example Kotlin code:

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 -> {                        // Handling an error 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    }}
Was this article helpful?