Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Differentiation of access permissions for user groups
    • Inviting a new user and assigning roles
    • Creating an L7 load balancer with a Smart Web Security profile through an Application Load Balancer ingress controller
    • Creating a distributed infrastructure with secure access
    • Centralized online publication and DDoS protection of applications
    • Basic SWS setup
    • Emergency DDoS protection in Application Load Balancer, L7
    • Delivering logs from a VM instance to Cloud Logging
    • Writing load balancer logs to PostgreSQL
    • Secure storage of GitLab CI passwords as Yandex Lockbox secrets
    • Service account with an OS Login profile for VM management via Ansible
    • Transferring logs from Container Optimized Image to Cloud Logging
    • Adding an HTML page to work with SmartCaptcha
    • Configuring alerts and dashboards in Monitoring
    • Uploading audit logs to MaxPatrol SIEM
    • Uploading audit logs to Splunk SIEM
    • Uploading audit logs to ArcSight SIEM
      • CAPTCHA in Android apps
      • Invisible CAPTCHA in Android apps
      • CAPTCHA in an Android app on Flutter
      • CAPTCHA in iOS apps
    • Server-side encryption for an Object Storage bucket
    • Encrypting secrets in Hashicorp Terraform
    • Managing KMS keys with Hashicorp Terraform
    • Auto Unseal in Hashicorp Vault
    • Transferring Yandex MPP Analytics for PostgreSQL cluster logs to Yandex Cloud Logging

In this article:

  • Getting started
  • Create a JavaScript Interface
  • Configure WebView to work with CAPTCHA
  • Retrieve the CAPTCHA test results
  1. Security
  2. SmartCaptcha use cases
  3. CAPTCHA in Android apps

Yandex SmartCaptcha in Android apps

Written by
Yandex Cloud
Updated at December 3, 2025
  • Getting started
  • Create a JavaScript Interface
  • Configure WebView to work with CAPTCHA
  • Retrieve the CAPTCHA test results

To embed SmartCaptcha in an Android app:

  1. Create JavaScript Interface.
  2. Configure WebView to work with CAPTCHA.
  3. Retrieve the CAPTCHA test results.

Getting startedGetting started

  1. Host an HTML page on your server or use the https://smartcaptcha.cloud.yandex.ru/webview page on the Yandex Cloud server.
  2. Create a CAPTCHA.
  3. See the Overview tab to get the CAPTCHA keys:
    • Client key: To load the page with CAPTCHA.
    • Server key: To get the CAPTCHA challenge results.

Create a JavaScript InterfaceCreate a JavaScript Interface

  1. Create a class to receive messages using a callback function from your web page with CAPTCHA.

  2. Define the onGetToken(token: String) method with the @JavascriptInterface annotation. It is called when the web page returns a token for passing CAPTCHA verification:

    class WebJsInterface {
    
      @JavascriptInterface
      fun onGetToken(token: String) {
        //Your code.
      }
    }
    

Configure WebView to work with CAPTCHAConfigure WebView to work with CAPTCHA

  1. Create a WebView and add it to the screen.

  2. Upload the URL of the web page with CAPTCHA to the WebView.

  3. Insert this query parameter into the URL: sitekey=<client_side_key>:

    val webView = findViewById<WebView>(R.id.webViewCaptcha)
    webView.loadUrl("CAPTCHA_page_URL?sitekey=<client_side_key>")
    
  4. Add the created JavaScript Interface object to the WebView. Specify NativeClient as the second parameter (this is where the web page will send messages using a callback function):

    settings.javaScriptEnabled = true // Enables JavaScript execution.
    addJavascriptInterface(WebJsInterface(), "NativeClient")
    

Retrieve the CAPTCHA test resultsRetrieve the CAPTCHA test results

  1. Save the CAPTCHA verification passed token. It will be returned in the onGetToken(token: String) method after the service processes an attempt.

  2. To validate the token, send a POST request to https://smartcaptcha.cloud.yandex.ru/validate, providing the following parameters in x-www-form-urlencoded format:

    • secret: Server key.
    • token: One-time token received after passing the check.
    • ip: IP address of the user that originated the request to validate the token. This is an optional parameter, but we ask you to provide the user IP when making requests. This helps improve SmartCaptcha performance.

    Note

    This logic must be implemented on the backend. Make sure the secret secret key does not end up in the Android app itself.

    Request example:

    https://smartcaptcha.cloud.yandex.ru/validate?secret=<server_key>&ip=<user_IP_address>&token=<token>
    
  3. Get a server response. It contains a JSON object with the status and message fields.

    For example:

    • It is a human:
    {
      "status": "ok",
      "message": ""
    }
    
    • It is a robot:
    {
      "status": "failed",
      "message": ""
    }

Was the article helpful?

Previous
User group mapping in Keycloak
Next
Invisible CAPTCHA in Android apps
© 2025 Direct Cursus Technology L.L.C.