Android
Overview and resources
GeeTest Adaptive CAPTCHA Android SDK is available to developers who integrate Android native client development.
Environmental requirements
Item | Resources |
---|---|
Development object | Android 4.4+ |
Developing environment | Android Studio 4.1 |
Compilation tools | Gradle (extract jar and resource files for ant compilation) |
System dependent | None |
Third-party dependency of SDK | None |
Bundle increment | 60K |
Related resources
Item | Resource address |
---|---|
Product structure process | Communication process, interaction process |
FAQs | Error Code List |
SDK resource bundle | Download from GeeTest dashboard |
Installation
Integrate SDK
Download .zip
file from SDK
resource bundle link to get the latest sdk
.
Import SDK
Drag and drop .aar
file from the zip package to the libs
folder in the project. After that, check whether .aar
has been added to Library
, and add the following code under the build.gradle
of the project:
repositories { |
Add dependencies to the aar package manually (AAR does not pass third-party dependencies by default, so you need to add them manually):
implementation(name: 'geetest_captcha_android_vx.y.z_date', ext: 'aar') |
Non-Kotlin project configuration
build.gradle
configuration in root directory
ext.kotlin_version = "1.4.10" |
build.gradle
configuration in introducing module
apply plugin: 'kotlin-android' |
Note: If there is a conflict between kotlin versions, exclude kotlin dependencies (group: ‘org.jetbrains.kotlin’)
Add permission
<!--Required--Default Request--> |
Obfuscation rules
GeeTest SDK has been obfuscated. Please bring obfuscation rules when integrating, and don’t obfuscate SDK again
-dontwarn com.geetest.captcha.** |
If a resource obfuscation tool is used, add it to the whitelist for configuration
-dontwarn com.geetest.captcha.** |
Configure interface
Logic flow
- Configure initialization
- Start verification
- Get validation callback
- Destroy resources
As shown in the product workflow process, you need to set up Server interface in your backend first,
and configure it with captchaId
and Key
you got from GeeTest dashbaord.
Initialization
SDK initialization configuration information can be initialized by onCreate
or onCreateView
method
Method:
public static GTCaptcha4Client getClient(Context context); |
Parameter description:
Parameters | Type | Description |
---|---|---|
context | Context | The context object must be an Activity instance |
appId | String | APP_ID, required parameters |
config | GTCaptcha4Config | Parameter configuration object, not required |
init () method initializes pre-loading, and if initialized in onCreate or onCreateView methods, the verification process is loaded ahead of time to evoke verification more quickly. If init () when you need to invoke verification, the loading speed is slower than pre-loading, so it is recommended to initialize it in onCreate or onCreateView methods.
Start verification
Start verification process
Method:
public void verifyWithCaptcha(); |
Get verification callback
public GTCaptcha4Client addOnSuccessListener(OnSuccessListener listener); |
Sample code
gtCaptcha4Client.addOnSuccessListener(new GTCaptcha4Client.OnSuccessListener() { |
Release resources
Release resources in onDestroy()
public void onDestroy(){ |
Landscape and portrait mode switching
|
Sample code of Preloading method
|
Normal loading code sample
private void click(){ |
Refer to the official Demo for sample code details
Parameter configuration
Configure parameters through GTCaptcha4Config.Builder
Definition | Description |
---|---|
setParams | Additional parameters will be passed to the front-end js for use |
setDebug | Whether to debug mode, default is false, please set it to false online |
setLanguage | Specify the language, following the application language by default |
setCanceledOnTouchOutside | Click on, whether the area outside will disappear, and the default is true |
setTimeOut | Set timeout, unit ms, 10000 by default |
setResourcePath | Set the intermediate address and load the local html file by default |
setBackgroundColor | Set the background color, which is transparent by default |
build | Build the GTCaptcha4Config object |
Configure parameters through the setParams interface
Function | Parameters | Description |
---|---|---|
Current theme style | displayMode | Integer, 0: follow the system, 1: normal, 2: dull black, 3: color blind. Default is 0 |
Verify the display position | displayArea | String, center, bottom, center by default |
Protocol | protocol | String, https:// or http://, https:// by default |
Validate the size of the downward offset window | barHeight | Integer, unit: logical pixels, such as 14, not configured by default |
H5 obscuration background color | bgColor | String, following css rules, such as #000000ff, not configured by default |
Custom loading | loading | String, load the middle page locally, loading the relative path, such as ./loading.gif. Note: If this field is not transmitted by remote loading, it is not configured by default |
setParams Interface Configuration Sample
HashMap<String, Object> hashMap = new HashMap<>(); |
Note: The setParams
interface can only accept data of basic data types, strings, and JSONArray types