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's navigation.
Method parameters:
Parameter | Required | Type | Description |
|---|---|---|---|
|
| Domain for receiving the token after completing the captcha. Must match the domain specified in | |
|
| Link for launching the captcha widget in your application's frontend, received in the
| |
|
| Callback function, called after the captcha is completed |
Example of the method call:
VKCaptcha.openCaptcha(domain = domain,redirectUri = captchaUrl,listener = listener)
The VKCaptchaResultListener interface returns the captcha completion result.
Example:
interface VKCaptchaResultListener {fun onResult(result: VKCaptchaResult) {when (result) {is VKCaptchaResult.Success -> {val token = result.tokenrepeatRequest(token)}is VKCaptchaResult.Error -> {// Handle the error or captcha closure}}}}
Here:
-
VKCaptchaResult— a sealed class with the captcha completion result:VKCaptchaResult.Successreturns the token of successful captcha completion (token: String) and the domain where the captcha was performed (domain: String?);VKCaptchaResult.Errorreturns 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.
The VKCaptcha.closeCaptcha() method closes the captcha widget. It calls onResult with the VKCaptchaError.Cancelled error.
Example of the method call:
VKCaptcha.closeCaptcha()
The VKCaptcha.getToken() method returns the token of successful captcha completion.
Example of the method call:
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.
Example of the method call:
VKCaptcha.setLocale(Locale("ru"))