Package 

Interface IHCaptcha


  • 
    public interface IHCaptcha
    
                        

    hCaptcha client which allows invoking of challenge completion and listening for the result.

    Usage example:
    1. Get a client either using the site key or customize by passing a config:
       client = HCaptcha.getClient(this).verifyWithHCaptcha(YOUR_API_SITE_KEY)
       client = HCaptcha.getClient(this).verifyWithHCaptcha(com.hcaptcha.sdk.HCaptchaConfig)
    
       // Improve cold start by setting up the hCaptcha client
       client = HCaptcha.getClient(this).setup(com.hcaptcha.sdk.HCaptchaConfig)
       // ui rendering...
       // user form fill up...
       // ready for human verification
       client.verifyWithHCaptcha();
    2. Listen for the result and error events:
    
     client.addOnSuccessListener(new OnSuccessListener{@literal <}HCaptchaTokenResponse{@literal >}() {
               {@literal @}Override
                public void onSuccess(HCaptchaTokenResponse response) {
                    String userResponseToken = response.getTokenResult();
                    Log.d(TAG, "hCaptcha token: " + userResponseToken);
                    // Validate the user response token using the hCAPTCHA siteverify API
                }
            })
            .addOnFailureListener(new OnFailureListener() {
               {@literal @}Override
                public void onFailure(HCaptchaException e) {
                    Log.d(TAG, "hCaptcha failed: " + e.getMessage() + "(" + e.getStatusCode() + ")");
                }
            });
    
    • Method Summary

      Modifier and Type Method Description
      abstract HCaptcha setup() Prepare the client which allows to display a challenge dialog
      abstract HCaptcha setup(@NonNull() String siteKey) Constructs a new client which allows to display a challenge dialog
      abstract HCaptcha setup(@NonNull() HCaptchaConfig config) Constructs a new client which allows to display a challenge dialog
      abstract HCaptcha verifyWithHCaptcha() Shows a captcha challenge dialog to be completed by the user
      abstract HCaptcha verifyWithHCaptcha(@NonNull() String siteKey) Shows a captcha challenge dialog to be completed by the user
      abstract HCaptcha verifyWithHCaptcha(@NonNull() HCaptchaConfig config) Shows a captcha challenge dialog to be completed by the user
      abstract void reset() Force stop verification and release resources.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setup

         abstract HCaptcha setup()

        Prepare the client which allows to display a challenge dialog

      • setup

         abstract HCaptcha setup(@NonNull() String siteKey)

        Constructs a new client which allows to display a challenge dialog

        Parameters:
        siteKey - The hCaptcha site-key.
      • setup

         abstract HCaptcha setup(@NonNull() HCaptchaConfig config)

        Constructs a new client which allows to display a challenge dialog

        Parameters:
        config - Config to customize: size, theme, locale, endpoint, rqdata, etc.
      • verifyWithHCaptcha

         abstract HCaptcha verifyWithHCaptcha(@NonNull() String siteKey)

        Shows a captcha challenge dialog to be completed by the user

        Parameters:
        siteKey - The hCaptcha site-key.
      • verifyWithHCaptcha

         abstract HCaptcha verifyWithHCaptcha(@NonNull() HCaptchaConfig config)

        Shows a captcha challenge dialog to be completed by the user

        Parameters:
        config - Config to customize: size, theme, locale, endpoint, rqdata, etc.
      • reset

         abstract void reset()

        Force stop verification and release resources.