Android

Integration Requirements

Compliance Notice

The privacy policy of apps that integrate the TDBehavior module should be updated based on our Privacy Agreement with the following additional information:

(1) Function Description: To identify machine behavior fraud risks, the SDK needs to obtain relevant behavior information from you or your end users.

(2) Necessary Personal Information: Touch, scroll, swipe, screen edge swipe, scale behavior information; input behavior information (input type, number of times, input speed, input time); application foreground/background behavior information; browsing page names and dwell time behavior information; device orientation behavior information; gyroscope sensor behavior information; accelerometer sensor behavior information; mouse behavior information (web); keyboard behavior information (web)

(3) Other Optional Personal Information: None


1. SDK Integration

Gradle Integration

Add dependencies in the project's build.gradle file:

dependencies {
    // Behavior
    implementation 'com.trustdecision.android:behavior:1.4.4'
}

2. Call Behavior Collection Methods

Behavior collection methods are used to obtain user behavior data. The interface definition is as follows:

public class TDBehaviorResult {
    // Return code, 0 represents success
    public int code() {
        return this.code;
    }
    // Error message when failed
    public String msg() {
        return this.msg;
    }
    // Behavior collection data
    public String payload() {
        return this.payload;
    }
}
public class TDRisk {
    /**
     * Start behavior collection, write collected data to SDK internal container
     */
    public static void start();
    
    /**
    * End behavior collection, stop writing collected data to SDK internal container and clears data in SDK internal container;
    */
    public static void stop();
    
    /**
     * Return behavior collection result. If data exists in SDK internal container, returns success code == 0, 
     * and clears data in SDK internal container;
     * If no data exists in SDK internal container, returns code == 104 error code
     * 
     * @return TDBehaviorResult containing code, msg, payload fields
     */
    public static TDBehaviorResult collect();
}

Example Code

⚠️⚠️⚠️ Ensure that there is user behavior after calling start in the business interface, such as text input, click, swipe, etc. Otherwise, calling collect will return a 104 error code, indicating that no behavior data was collected;

public class LoginActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        
        // When entering business interface, call start method to begin behavior collection
        TDRisk.start();
    }
    
    private void onLoginButtonClick() {
        // When calling business interface, call collect method to get behavior collection data
        TDBehaviorResult result = TDRisk.collect();
        
        if (result.code() == 0) {
            Log.d("TD", "Successfully obtained behavior collection result, payload: " + result.payload());
        } else {
            Log.e("TD", "Failed to obtain behavior collection result, code: " + result.code() + ", msg: " + result.msg());
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // When leaving business interface, call stop method to end behavior collection
        TDRisk.stop();
    }
}

Specify input fields that do not require collected

Set the attribute tag including "TDBehaviorExInput" in EditText. After this setting, the text input events of EditText will no longer be collected

		EditText editText = new EditText(context);
		// will not collect EditText text input
		editText.setTag("otherKey,TDBehaviorExInput");

3.Return Codes

Error CodeDescriptionSolution
0SuccessNo action needed
100initWithOptions not calledinitWithOptions not called, need to call initWithOptions
101Network authentication result not returned due to low network speedThrow an error to the user: "Network failure, please check the network and try again", guiding the user to call the collect method again
102Network error in authentication interface due to system reasons, such as no network connectionThrow an error to the user: "Network failure, please check the network and try again", guiding the user to call the collect method again
103Authentication interface returns status code is not 200Check if partner parameters are correct. If still fails, provide error message resultStruct.msg to our operations team to confirm if parameters are correct and within validity period
104No data in SDK internal containerThere is no valid collect data,Please Ensure that there is user behavior after calling start in the business interface, such as text input, click, swipe, etc!
109No data in SDK internal containerThere is no valid collect data,Switches are all NO,Please contact TrustDecision!
110No data in SDK internal containerThere is no valid collect data,Please call the start method first!