SDK reference for Android
- Android version 5.0 (API 21) and above;
- Java version 11 and above;
- Kotlin version 1.9.0 and above.
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 for obtaining the token after passing the captcha. Must match the domain specified in | |
|
| Link to launch the captcha widget in your application frontend, obtained from the
| |
|
| Callback function invoked after the captcha is completed |
Method call example:
VKCaptcha.openCaptcha(domain = domain,redirectUri = captchaUrl,listener = listener)
The VKCaptchaResultListener interface returns the captcha result.
Example:
interface VKCaptchaResultListener {fun onResult(result: VKCaptchaResult) {when (result) {is VKCaptchaResult.Success -> {val token = result.tokenrepeatRequest(token)}is VKCaptchaResult.Error -> {// Error handling or captcha closure}}}}
Here:
-
VKCaptchaResult— a sealed class with the captcha result:VKCaptchaResult.Successreturns the token of successful captcha completion (token: String) and the domain where the captcha was performed (domain: String?);VKCaptchaResult.Errorreturns 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.
The VKCaptcha.closeCaptcha() method closes the captcha widget. It invokes onResult with the VKCaptchaError.Cancelled error.
Method call example:
VKCaptcha.closeCaptcha()
The VKCaptcha.getToken() method returns the token of successful captcha completion.
Method call example:
val token = VKCaptcha.getToken("<DOMAIN>")
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"))