logoドキュメント
検索
ログイン

Android SDK API

External Support Utility Class

Method

getClient(Context)

Retrieve the GTCaptcha4Client utility class object

Declaration

public static GTCaptcha4Client getClient(Context context)
              
              public static GTCaptcha4Client getClient(Context context)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
context Context Context object

Discussion

Note: This is not a singleton implementation. The GTCaptcha4Client object obtained through getClient() needs to be saved for use in onDestroy or other lifecycle methods.

init(String)

Initialize with default configuration

Declaration

public GTCaptcha4Client init(String captchaId)
              
              public GTCaptcha4Client init(String captchaId)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
captchaId String The captchaId applied for in the backend

Discussion

Note: Calling the init() method immediately starts the captcha loading process. If it is called before the onResume() lifecycle, the captcha will be preloaded. When verifyWithCaptcha() is executed to display the captcha, it will load and display quickly. The same applies below.

init(String, GTCaptcha4Config)

Initialize with custom configuration

Declaration

public GTCaptcha4Client init(String captchaId, GTCaptcha4Config config)
              
              public GTCaptcha4Client init(String captchaId, GTCaptcha4Config config)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
captchaId String The captchaId applied for in the backend
config GTCaptcha4Config Configuration object

addOnSuccessListener(GTCaptcha4Client.OnSuccessListener)

Add a listener for verification results, which is called back when the captcha is successfully loaded and the user solves the captcha.

Declaration

public GTCaptcha4Client addOnSuccessListener(GTCaptcha4Client.OnSuccessListener response)
              
              public GTCaptcha4Client addOnSuccessListener(GTCaptcha4Client.OnSuccessListener response)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
response GTCaptcha4Client.OnSuccessListener Verification result listener

addOnFailureListener(GTCaptcha4Client.OnFailureListener)

Add a listener for captcha loading failure, which is triggered when an error occurs during the captcha loading process.

Declaration

public GTCaptcha4Client addOnFailureListener(GTCaptcha4Client.OnFailureListener listener)
              
              public GTCaptcha4Client addOnFailureListener(GTCaptcha4Client.OnFailureListener listener)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
listener GTCaptcha4Client.OnFailureListener Listener for captcha load failure

addOnWebViewShowListener(GTCaptcha4Client.OnWebViewShowListener)

Add a listener for successful frontend verification loading. When the frontend verification is successfully loaded, the callback is triggered. If preloading is completed, the callback is triggered immediately after calling verifyWithCaptcha.

Declaration

public GTCaptcha4Client addOnWebViewShowListener(GTCaptcha4Client.OnWebViewShowListener listener)
              
              public GTCaptcha4Client addOnWebViewShowListener(GTCaptcha4Client.OnWebViewShowListener listener)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
listener GTCaptcha4Client.OnWebViewShowListener Listener for successful frontend verification loading

verifyWithCaptcha()

Start the verification process and load the captcha.

Declaration

public GTCaptcha4Client verifyWithCaptcha()
              
              public GTCaptcha4Client verifyWithCaptcha()

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

Note: Before calling verifyWithCaptcha(), you need to call init(), addOnSuccessListener(), and addOnFailureListener(); otherwise, errors may occur.

cancel()

Cancel the verification and close the verification window.

Declaration

public void cancel()
              
              public void cancel()

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

Note: Before calling cancel(), you need to call init(), addOnSuccessListener(), and addOnFailureListener(); otherwise, errors may occur.

setLogEnable(boolean enable)

Enable or disable log monitoring.

Declaration

public void setLogEnable(boolean enable)
              
              public void setLogEnable(boolean enable)

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

Calling setLogEnable controls the log printing functionality.

destroy()

Destroy resources with a long lifecycle.

Declaration

public void destroy()
              
              public void destroy()

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

Destroy verification resources. This method must be called.

Discussion

This method should be called during the onDestroy lifecycle of the captcha interface used by the client.

configurationChanged(Configuration)

Handle screen orientation changes.

Declaration

public void configurationChanged(Configuration newConfig)
              
              public void configurationChanged(Configuration newConfig)

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

This method should be called during the onConfigurationChanged lifecycle method for screen orientation changes.

getVersion()

Retrieve the version number.

Declaration

public static String getVersion()
              
              public static String getVersion()

            
このコードブロックはフローティングウィンドウ内に表示されます

Return Value

Returns the version number as a String.

isSupportWebView(Context)

Check whether the system supports WebView. If not supported, it is recommended to use a fallback logic.

Declaration

public static Pair<Boolean, String> isSupportWebView(Context context)
              
              public static Pair<Boolean, String> isSupportWebView(Context context)

            
このコードブロックはフローティングウィンドウ内に表示されます

Return Value

Description of the Pair object:

Param Type Description
first Boolean Whether WebView is supported. If not, fallback logic can be used.
second String Error description for loading the WebView object

GTCaptcha4Config#Builder

Parameter configuration class.

setTimeOut(int)

Set the request timeout duration.

Declaration

public Builder setTimeOut(int timeOut)
              
              public Builder setTimeOut(int timeOut)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
timeOut int Unit: ms, default is 10000

setResourcePath(String)

Set the resource path for WebView loading.

Declaration

public Builder setResourcePath(String html)
              
              public Builder setResourcePath(String html)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
html String The address for WebView loading

Discussion

By default, it loads the gt4-index*.html file in the assets directory. This interface does not need to be set unless there are special requirements.

setLanguage(String)

Set the language for JS transmission. This interface can only control the language of the loaded WebView, while the SDK's language follows the current application.

Declaration

public Builder setLanguage(String language)
              
              public Builder setLanguage(String language)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
language String Short code for supported frontend languages. Refer to the frontend documentation for details.

Discussion

If set to null or not set, the default language short code of the application will be transmitted to the frontend.

setCanceledOnTouchOutside(boolean)

Set whether clicking the gray area will dismiss the dialog. The default is to dismiss.

Declaration

public Builder setCanceledOnTouchOutside(boolean canceledOnTouchOutside)
              
              public Builder setCanceledOnTouchOutside(boolean canceledOnTouchOutside)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
canceledOnTouchOutside boolean true to dismiss

setDebug(boolean)

Set whether it is in debug mode. For production, it must be set to false or not configured.

Declaration

public Builder setDebug(boolean debug)
              
              public Builder setDebug(boolean debug)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
debug boolean true for debug, default is false

setBackgroundColor(int)

Sets the background color of WebView, which controls the background color of the Android WebView component and is different from the background color of the front-end JS.

Declaration

public Builder setBackgroundColor(int backgroundColor)
              
              public Builder setBackgroundColor(int backgroundColor)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
backgroundColor int Color resource address or the return value of Color.parseColor()

setDialogStyle(String)

Sets the theme style of the verification dialog box.

Declaration

public Builder setDialogStyle(String dialogStyle)
              
              public Builder setDialogStyle(String dialogStyle)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
dialogStyle String Name of the dialog theme style

Declaration

The following is the default theme style:

<style name="gt4_captcha_dialog_style" parent="android:Theme.Dialog"> <!-- No window frame for the Dialog --> <item name="android:windowFrame">@null</item> <!-- Whether it floats above the activity --> <item name="android:windowIsFloating">true</item> <!-- Whether it is translucent --> <item name="android:windowIsTranslucent">true</item> <!-- Removes the title --> <item name="android:windowNoTitle">true</item> <item name="android:windowContentOverlay">@null</item> <!-- Whether to use a black translucent background outside the display area --> <item name="android:backgroundDimEnabled">true</item> <!-- Sets the background of the dialog --> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:padding">0dp</item> </style>
              
              <style name="gt4_captcha_dialog_style" parent="android:Theme.Dialog">
    <!-- No window frame for the Dialog -->
    <item name="android:windowFrame">@null</item>
    <!-- Whether it floats above the activity -->
    <item name="android:windowIsFloating">true</item>
    <!-- Whether it is translucent -->
    <item name="android:windowIsTranslucent">true</item>
    <!-- Removes the title -->
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <!-- Whether to use a black translucent background outside the display area -->
    <item name="android:backgroundDimEnabled">true</item>
    <!-- Sets the background of the dialog -->
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:padding">0dp</item>
</style>

            
このコードブロックはフローティングウィンドウ内に表示されます

setDialogShowListener(GTCaptcha4Client.OnDialogShowListener)

Sets the listener callback for when the verification window is displayed.

Declaration

public void setDialogShowListener(GTCaptcha4Client.OnDialogShowListener dialogShowListener)
              
              public void setDialogShowListener(GTCaptcha4Client.OnDialogShowListener dialogShowListener)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
dialogShowListener GTCaptcha4Client.OnDialogShowListener Listener object for the verification window display

setParams(Map<String, Object>)

Configures additional parameters, which are fully passed to JS.

Declaration

public Builder setParams(Map<String, Object> params)
              
              public Builder setParams(Map<String, Object> params)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param Type Description
params JSONObject Additional configuration parameter

Discussion

Supported key-value pairs are as follows:

Key ValueType Description Default Value
displayMode int Theme style, 0: Follow system, 1: Normal, 2: Dark mode 0
protocol String Protocol header, supports "https:// or http:// https://
bgColor String Verification background mask color, follows CSS rules, note the last two digits for transparency #00000000
loading String Custom loading, relative path of the loading resource for WebView loading HTML, an empty string means no loading effect "/gt4-loading.gif"
rem float Sets the overall scaling ratio of the verification code 1
hideBar JSONArray Hides the close button and refresh button on subsequent verification screens N/A
nextWidth String Width of the verification code popup, must include units, e.g., "300px" N/A
riskType String Specifies the verification form in conjunction with risk control N/A
hideSuccess boolean Hides the verification success popup FALSE

Sample Code

Map<String, Object> params = new HashMap<>(); params.put("displayMode", 0); params.put("protocol", "https://"); params.put("bgColor", "#CC0000FF"); params.put("loading", "./loading_test.gif"); params.put("rem", 0.6); JSONArray hideBar = new JSONArray() .put("close") .put("refresh"); params.put("hideBar", hideBar); params.put("nextWidth", "300px"); params.put("hideSuccess", true); GTCaptcha4Config.Builder builder = new GTCaptcha4Config.Builder() .setParams(params);
              
              Map<String, Object> params = new HashMap<>();
params.put("displayMode", 0);
params.put("protocol", "https://");
params.put("bgColor", "#CC0000FF");
params.put("loading", "./loading_test.gif");
params.put("rem", 0.6);
JSONArray hideBar = new JSONArray()
        .put("close")
        .put("refresh");
params.put("hideBar", hideBar);
params.put("nextWidth", "300px");
params.put("hideSuccess", true);

GTCaptcha4Config.Builder builder = new GTCaptcha4Config.Builder()
        .setParams(params);

            
このコードブロックはフローティングウィンドウ内に表示されます

build()

Constructs a GTCaptcha4Config object to be used with the init() interface.

Declaration

public GTCaptcha4Config build()
              
              public GTCaptcha4Config build()

            
このコードブロックはフローティングウィンドウ内に表示されます

GTCaptcha4Client#OnSuccessListener

Callback listener for verification results.

onSuccess(Boolean, String)

Verification interface callback.

Declaration

void onSuccess(Boolean status, String response)
              
              void onSuccess(Boolean status, String response)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param |Type | Description ------ |-----|----- status |Boolean | Result of user operation verification, true for success, false for failure. Failure will refresh the verification style. response | String | When user operation verification succeeds, the response data needs to be sent to the server for verification.

Discussion

Description of successful verification:

{"lot_number":"b150e61198924eff9eaae121e9b67aa8","pass_token":"6fcfba4c35cb57b873c99c5b3b02089c58a26244c18f7706aaa1e87aed3aa8f4","gen_time":"1622020720","captcha_output":"Tu6rW0dRNO0NLxMKftwdH00G5whF5HHddthoXSEA1G4="}
              
              {"lot_number":"b150e61198924eff9eaae121e9b67aa8","pass_token":"6fcfba4c35cb57b873c99c5b3b02089c58a26244c18f7706aaa1e87aed3aa8f4","gen_time":"1622020720","captcha_output":"Tu6rW0dRNO0NLxMKftwdH00G5whF5HHddthoXSEA1G4="}

            
このコードブロックはフローティングウィンドウ内に表示されます

Description of failed verification:

{"captchaId":"647f5ed2ed8acb4be36784e01556bb71","captchaType":"slide","challenge":"95ed53b4-95c6-4c6b-9aac-769b29ef74a0"}
              
              {"captchaId":"647f5ed2ed8acb4be36784e01556bb71","captchaType":"slide","challenge":"95ed53b4-95c6-4c6b-9aac-769b29ef74a0"}

            
このコードブロックはフローティングウィンドウ内に表示されます

GTCaptcha4Client#OnFailureListener

Callback listener for loading failure.

onFailure(String)

Loading failure callback.

Declaration

void onFailure(String error)
              
              void onFailure(String error)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param |Type | Description ------ |-----|----- error | String | Description of verification loading failure. Note: Includes user-initiated cancellation.

Discussion

Description of loading failure:

{"code":"-14460","msg":"Verification session has been canceled","desc":{"description":"User cancelled 'Captcha'"}}
              
               {"code":"-14460","msg":"Verification session has been canceled","desc":{"description":"User cancelled 'Captcha'"}}

            
このコードブロックはフローティングウィンドウ内に表示されます

GTCaptcha4Client#OnWebViewShowListener

Callback listener for successful front-end verification loading.

onWebViewShow()

Front-end verification loading success.

Declaration

void onWebViewShow()
              
              void onWebViewShow()

            
このコードブロックはフローティングウィンドウ内に表示されます

Discussion

Callback after front-end verification loading is successful. If preloading is completed, this callback is triggered immediately after calling verifyWithCaptcha.

GTCaptcha4Client#OnDialogShowListener

Callback listener for the display of the verification window.

actionBeforeDialogShow(Dialog)

Callback before the verification window is displayed.

Declaration

void actionBeforeDialogShow(Dialog dialog)
              
              void actionBeforeDialogShow(Dialog dialog)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param |Type | Description ------ |-----|----- dialog | Dialog | Instance of the verification window.

actionAfterDialogShow()

Callback after the verification window is displayed.

Declaration

void actionAfterDialogShow(Dialog dialog)
              
              void actionAfterDialogShow(Dialog dialog)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param |Type | Description ------ |-----|----- dialog | Dialog | Instance of the verification window.

Discussion

You can change system styles here, such as hiding the navigation bar, hiding the status bar, etc.

onDialogFocusChanged()

Callback when the focus of the verification window changes.

Declaration

void onDialogFocusChanged(Dialog dialog, boolean hasFocus)
              
              void onDialogFocusChanged(Dialog dialog, boolean hasFocus)

            
このコードブロックはフローティングウィンドウ内に表示されます

Parameters

Param |Type | Description ------ |-----|----- dialog |Dialog | Instance of the verification window. hasFocus | boolean | Whether it has focus.

icon
お問い合わせ