VK Cloud logo

SDK reference for Android

System requirements

  • Android version 5.0 (API 21) and above;
  • Java version 11 and above;
  • Kotlin version 1.9.0 and above.

Display captcha

The VKCaptcha.openCaptcha() method displays the captcha to the user in an Android application. The captcha is displayed as an Activity and integrates into the application navigation.

Method parameters:

Parameter

Required

Type

Description

domain

SDK reference for Android

string

Domain for obtaining the token after passing the captcha. Must match the domain specified in redirectUri

redirectUri

SDK reference for Android

string

Link to launch the captcha widget in your application frontend, obtained from the link parameter in the response of the method GET /captchaNotRobot.createSession. Contains the session token and metadata:

  • domain — domain where the captcha will be used;
  • session_token — session token;
  • variant — captcha display type (block or popup)

listener

SDK reference for Android

VKCaptchaResultListener

Callback function invoked after the captcha is completed

Method call example:

VKCaptcha.openCaptcha(domain = domain,redirectUri = captchaUrl,listener = listener)

Get captcha result

The VKCaptchaResultListener interface returns the captcha result.

Example:

interface VKCaptchaResultListener {    fun onResult(result: VKCaptchaResult) {        when (result) {            is VKCaptchaResult.Success -> {                val token = result.token                repeatRequest(token)            }            is VKCaptchaResult.Error -> {                // Error handling or captcha closure            }        }    }    }

Here:

  • VKCaptchaResult — a sealed class with the captcha result:

    • VKCaptchaResult.Success returns the token of successful captcha completion (token: String) and the domain where the captcha was performed (domain: String?);
    • VKCaptchaResult.Error returns an error that occurred during captcha completion (error: VKCaptchaError) and the domain where the captcha was performed (domain: String?).
  • VKCaptchaError — a sealed class with errors that occur during captcha completion:

    • NetworkError(message, error) — network error;
    • IllegalArgumentError(message) — error in the provided parameters;
    • Cancelled() — the captcha was closed by the user;
    • WebviewIsUpdatingError(message, error) — error when updating System WebView.

Close captcha

The VKCaptcha.closeCaptcha() method closes the captcha widget. It invokes onResult with the VKCaptchaError.Cancelled error.

Method call example:

VKCaptcha.closeCaptcha()

Get successful captcha completion token

The VKCaptcha.getToken() method returns the token of successful captcha completion.

Method call example:

val token = VKCaptcha.getToken("<DOMAIN>")

Select captcha language

The VKCaptcha.setLocale() method sets the captcha localization language. The system language is used by default.

Possible values:

  • ru — Russian;
  • be — Belarusian;
  • de — German;
  • en — English;
  • es — Spanish;
  • fr — French;
  • kk — Kazakh;
  • pl — Polish;
  • tr — Turkish;
  • uk — Ukrainian;
  • uz — Uzbek.

Method call example:

VKCaptcha.setLocale(Locale("ru"))