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 the 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's navigation.

Method parameters:

Parameter

Required

Type

Description

domain

SDK reference for Android

string

Domain for receiving the token after completing the captcha. Must match the domain specified in redirectUri

redirectUri

SDK reference for Android

string

Link for launching the captcha widget in your application's frontend, received in the link parameter in the response of the GET /captchaNotRobot.createSession method. Contains a 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, called after the captcha is completed

Example of the method call:

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

Get the captcha completion result

The VKCaptchaResultListener interface returns the captcha completion result.

Example:

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

Here:

  • VKCaptchaResult — a sealed class with the captcha completion 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 the error that occurred during the captcha completion (error: VKCaptchaError) and the domain where the captcha was performed (domain: String?).
  • VKCaptchaError — a sealed class with the errors that occur during the captcha completion:

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

Close the captcha

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

Example of the method call:

VKCaptcha.closeCaptcha()

Get the successful captcha completion token

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

Example of the method call:

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

Select the 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.

Example of the method call:

VKCaptcha.setLocale(Locale("ru"))
Was this article helpful?