Android SDK integration

2022.01.14 14:05:33

    Brand-new man-machine method, efficient interception of machine behavior, line of defense. Equipped with the risk-first adventure engine, intelligent attack is difficult, safe, and attack intensity is high. The screen-reading software is deeply adapted, and the visually impaired group can also use it easily. , In line with the non-equipment requirements of the Ministry of Industry and Information Technology

    Compatibility

    Column illustrate
    adapter version minSdkVersion 16

    Integrate SDK

    maven(recommend)

    Starting from version 3.2.2, a remote dependency method is provided, and the local dependency method is gradually eliminated. Local dependency integration is replaced with remote dependency, please remove the clean local package first to avoid repeated dependency conflicts

    Confirm that mavenCentral support is configured in the build.gradle of the project root directory

    buildscript {
        repositories {
            mavenCentral()
        }
        ...
    }
    
    allprojects {
        repositories {
            mavenCentral()
        }
    }
    

    Add dependencies in the build.gradle of the corresponding module

    implementation 'io.github.yidun:captcha:3.3.0.1'
    

    Manual integration

    Get SDK

    Download the aar package for verification code sdk from github Click to download

    Import the SDK

    Copy the obtained aar file to the libs folder of the corresponding module (if there is no such directory, you need to create a new one), and then add the following code to the build.gradle file

    android{
        repositories {
            flatDir {
                dirs 'libs'
            }
        } 
    }    
    
    dependencies {
        implementation(name: 'captcha-release-3.2.4', ext: 'aar')
        implementation(name: 'base-core-1.0.3', ext: 'aar')
    }
    

    Various configurations

    Obfuscated configuration

    Add the following obfuscation rules to the proguard-rules.pro file

    -keepattributes *Annotation*
    -keep public class com.netease.nis.captcha.**{*;}
    
    -keep public class android.webkit.**
    
    -keepattributes SetJavaScriptEnabled
    -keepattributes JavascriptInterface
    
    -keepclassmembers class * {
        @android.webkit.JavascriptInterface <methods>;
    }
    

    Quick call example

    public class DemoActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            CaptchaConfiguration captchaConfiguration = new CaptchaConfiguration.Builder().
                    captchaId("bussiness id").
                    listener(new CaptchaListener() {
                        @Override
                        public void onReady() {
                        }
    
                        @Override
                        public void onValidate(String result, String validate, String msg) {
                        }
    
                        @Override
                        public void onError(int code, String msg) {
                        }
    
                        @Override
                        public void onClose(Captcha.CloseType closeType) {
                        }
                    })
                    .build(this);
            Captcha captcha = Captcha.getInstance().init(captchaConfiguration);
            captcha.validate();
        }
    }
    

    For more usage scenarios, please refer to demo

    SDK api description

    1. Get Captcha singleton object

    Code description

    Captcha captcha = Captcha.getInstance()
    

    2. initialization

    Code description

    captcha.init(CaptchaConfiguration configuration)
    

    CaptchaConfiguration configurable element description

    CaptchaConfiguration adopts the builder mode, and the configurable items are configured through CaptchaConfiguration.Builder()

    item parameter/type have to default describe
    captchaId captchaId:String yes without Business id
    listener listener:CaptchaListener yes without callback
    mode mode:ModeType no ModeType.MODE_CAPTCHA Verification code type
    timeout timeout:long no 10 overtime/s
    backgroundDimAmount amount:float no 0.5 transparency
    controlBarImageUrl startIconUrl:String,movingIconUrl:String,errorIconUrl:String no without Picture of the slider
    position xCoordinate:int,yCoordinate:int no -1,-1 window position
    debug isEnableDebug:boolean no false enable debug
    languageType langType:LangType no LangType.LANG_ZH_CN language type
    touchOutsideDisappear isDisappear:boolean no true close when touching the outside
    useDefaultFallback useDefaultFallback:boolean no true use the default downgrade
    failedMaxRetryCount failedMaxRetryCount:int no 3 Maximum number of errors to trigger downgrade
    hideCloseButton isHideCloseButton:boolean no false hide the close button
    protocol protocol:String no https resource loading protocol: http or https
    loadingText text:String no without load copy
    loadingTextId loadingTextId:int no without Load the copy by setting the resource id
    loadingAnimResId loadingAnimResId:int no without loading animation
    ModeType description
    public enum ModeType {
            /**
             * Traditional Type
             */
            MODE_CAPTCHA,
            /**
             * Non-sense Type
             */
            MODE_INTELLIGENT_NO_SENSE,
    }
    

    LangType description

    public enum LangType {
            LANG_ZH_CN,//Simplified Chinese
            LANG_ZH_TW,//traditional Chinese
            LANG_EN,//English
            LANG_JA,//Japanese
            LANG_KO,//Korean
            LANG_TH,//Thai
            LANG_VI,//Vietnamese
            LANG_FR,//French
            LANG_AR,//Arabic
            LANG_RU,//Russian
            LANG_DE,//German
            LANG_IT,//Italian
            LANG_HE,//Hebrew
            LANG_HI,//Hindi
            LANG_ID,//Indonesian
            LANG_MY,//Burmese
            LANG_LO,//Lao
            LANG_MS,//Malay
            LANG_PL,//Polish
            LANG_PT,//Portuguese
            LANG_ES,//Spanish
            LANG_TR,//Turkish
    }
    
    CaptchaListener Interface Description
    public interface CaptchaListener {
        // Verification code is ready
        void onReady();
    
        /**
         * After validation, the result is validated if validate is not empty, then the validation is passed
         * @param result result
         * @param validate
         * @param msg
         */
        void onValidate(String result, String validate, String msg);
    
        /**
         * Exception callback
         * @param code
         * @param msg
         */
        void onError(int code, String msg);
    
        /**
         * Call back when the verification code box is closed
         *
         * @param closeType Close type enumeration value,{@see Captcha#CloseType}
         */
        void onClose(Captcha.CloseType closeType);
    }
    
    CloseType description
    public enum CloseType {
            /**
             * User actively closed
             */
            USER_CLOSE,
            /**
             * The verification code is successfully verified and the process is automatically closed
             */
            VERIFY_SUCCESS_CLOSE,
    
            /**
             * loading close
             */
            TIP_CLOSE
    }
    

    3. Pop-up verification code

    Code description

    After the verification code is successfully verified, the page stays for 500 milliseconds before closing the verification code

    captcha.validate()
    

    4. Switch between horizontal and vertical screens

    Set the configChanges of the corresponding Activity in AndroidManifest to

     android:configChanges="keyboardHidden|orientation|screenSize"
    

    Code description

    Called in the onConfigurationChanged life cycle

    captcha.changeDialogLayout()
    

    5. Turn off verification code related resources(Put on onDestroy)

    Code description

    captcha.destroy()
    

    6. Separately close all verification code related Dialogs

    Code description

    captcha.dismissAllDialog()
    
    Online Chat Tel:95163223