Connecting to a mobile application on Android
-
Download VK Капча SDK:
Maven-
Add the Maven repository to
dependencyResolutionManagementorsettings.gradle.kts:dependencyResolutionManagement {repositories {maven(url = "https://artifactory-external.vkpartner.ru/artifactory/vkid-sdk-android/")}} -
Add the library to your application module's
build.gradle.kts:dependencies {implementation("com.vk.id.captcha:vkid-captcha:<VERSION>")}Here
<VERSION>is the VK Капча SDK version for Android (0.0.13). -
In your application's
Android Manifest, override theauthorityof the provider that initializes the SDK:<application><providerandroid:name="com.vk.id.captcha.init.SdkInitContentProvider"android:authorities="your.unique.authority"android:exported="false"tools:replace="authorities" /></application>
-
-
Get a link from the backend to launch the captcha widget.
-
(Optional) Configure the captcha localization language. Use the SDK method
VKCaptcha.setLocale(). -
Display the captcha to the user. Use the SDK method
VKCaptcha.openCaptcha(). -
Handle the captcha completion result using the interface
VKCaptchaResultListener:-
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.
-
Kotlin code example:
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.tokenrepeatRequest(token)}is VKCaptchaResult.Error -> {// Error handling 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}}