Overview
GeeTest captcha Android SDK supports for native Android.
Development environment
Item | Description |
---|---|
Target | Android 4.0+ |
Development environment | Android Studio 3.6.0 |
Compile tool | gradle (for ant compile, extract SDK, jar package and resource file access) |
System dependency | None |
Third-party dependency | OKHTTP |
Dependency in demo | OKHTTP |
Resources
tem | Description |
---|---|
Data communication flow chart | Data communication flow chart , Interaction process |
SDK API reference | Check gt3-android-docs or the comments in examples |
Custom API documentation | Document download |
Error code | Error code |
Installation
Download SDK
Remote dependency acquisition
The code is hosted in jcenter. Check if the jcenter() configuration is declared in the main project build.gradle file before using it
# Compatible androidx |
Manual download fetch
Please click the link below to download the latest SDK (in .zip
format) (Compatible androidx).
Import SDK(If there is a demand on the Google Store, please use the manual download integration method)
Except using the remote repository, you can also drag and drop the .aar
file into libs
folder.
After adding the .aar
file into the libs
folder, please check if .aar
has been successfully imported into Library. Please insert the following code into the build.gradle of your project.
repositories { |
Then, add dependency for .aar
package manually (AAR does not pass third-party dependencies by default, you need to manually add!).
compile(name: 'geetest_sensebot_android_vx.y.z_date', ext: 'aar') |
Configure API
Android sdk provide the following APIs.
- captcha initialization
- Start captcha verification
- Get the verification callback data
Please firstly integrate server SDK, configure the id
and key
(get from GeeTest dashboard), then implement API1
and API2
in the captcha initialization method.
Please refer to the following code example for integration.
Compile and run your project
Compile your project and test GeeTest captcha.
Two integration options
Bind GeeTest captcha to a custom button
Integrate with GeeTest captcha button
Code example
File configuration
Set permission
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />Proguard rules
# GeeTest SDK has already been obfuscated, please do not obfuscate it again
-dontwarn com.geetest.sdk.**
-keep class com.geetest.sdk.**{*;}
Bind GeeTest captcha to a custom button
New a captcha object
Please new the object within the lifecycle of
oncreate
// Please initialize it in the oncreate method to get enough gesture data to ensure a successful first round of validation
GT3GeetestUtils gt3GeetestUtils = new GT3GeetestUtils(this);
Configure parameters for captcha initialization
Configure it in the life cycle of
oncreate
or configure it when it has been called// 配置bean文件,也可在oncreate初始化
gt3ConfigBean = new GT3ConfigBean();
// 设置验证模式,1:bind,2:unbind
gt3ConfigBean.setPattern(1);
// 设置点击灰色区域是否消失,默认不消息
gt3ConfigBean.setCanceledOnTouchOutside(false);
// 设置语言,如果为null则使用系统默认语言
gt3ConfigBean.setLang(null);
// 设置加载webview超时时间,单位毫秒,默认10000,仅且webview加载静态文件超时,不包括之前的http请求
gt3ConfigBean.setTimeout(10000);
// 设置webview请求超时(用户点选或滑动完成,前端请求后端接口),单位毫秒,默认10000
gt3ConfigBean.setWebviewTimeout(10000);
// 设置回调监听
gt3ConfigBean.setListener(new GT3Listener());
gt3GeetestUtils.init(gt3ConfigBean);
// 开启验证
gt3GeetestUtils.startCustomFlow();
Integrate with GeeTest captcha button
Insert captcha button
<com.geetest.sdk.views.GT3GeetestButton
android:id="@+id/btn_geetest"
android:layout_width="290dp"
android:layout_height="44dp"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal" />New a captcha object
Please new the object in the life cycle of
oncreate
// 务必在oncreate方法里配置
GT3GeetestButton geetestButton = (GT3GeetestButton) findViewById(R.id.btn_geetest);
GT3GeetestUtils gt3GeetestUtils = new GT3GeetestUtils(this);Configure parameter for captcha initialization
Configure it in the life cycle of
oncreate
or configure it when it has been called// 配置bean文件,也可在oncreate初始化
gt3ConfigBean = new GT3ConfigBean();
// 设置验证模式,1:bind,2:unbind
gt3ConfigBean.setPattern(2);
// 设置点击灰色区域是否消失,默认不消息
gt3ConfigBean.setCanceledOnTouchOutside(false);
// 设置语言,参考API文档。如果为null则使用系统默认语言(TODO 若想设置语言立即生效,则init需要在setContentView之前)
gt3ConfigBean.setLang(null);
// 设置加载webview超时时间,单位毫秒,默认10000,仅且webview加载静态文件超时,不包括之前的http请求
gt3ConfigBean.setTimeout(10000);
// 设置webview请求超时(用户点选或滑动完成,前端请求后端接口),单位毫秒,默认10000
gt3ConfigBean.setWebviewTimeout(10000);
// 设置回调监听
gt3ConfigBean.setListener(new GT3Listener());
gt3GeetestUtils.init(gt3ConfigBean);
// 绑定
geetestButton.setGeetestUtils(gt3GeetestUtils);
Handle captcha callback
To deal with the callback data during the verification, you need to process API1 request via onButtonClick
method, and process API2 request via onDialogResult
method.
|
Please refer to the demo project for detailed examples.