Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Differentiation of access permissions for user groups
    • Creating an L7 load balancer with a Smart Web Security security profile through an Application Load Balancer Ingress controller
    • Centralized online publication and app protection against DDoS attacks
    • 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
    • Creating an L7 load balancer with a security profile
    • Alert settings in Monitoring
    • Exporting audit logs to MaxPatrol SIEM
    • Exporting audit logs to SIEM Splunk systems
    • 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

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 January 23, 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.yandexcloud.net/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.yandexcloud.net/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.yandexcloud.net/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.

    Here is an 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.