# Machine Learning Consent

The Machine Learning Consent module captures the user's consent to process their biometric data for machine-learning purposes. It records their response on the server. You choose the consent text variant (US or GDPR style) that matches your compliance needs.

There is no Dashboard equivalent for this module, so you cannot use [integration Pattern 3](https://developer.incode.com/docs/android-common-implementation-patterns#pattern-3-run-flows-configured-in-dashboard) to add it. You must use [Pattern 1](https://developer.incode.com/docs/android-common-implementation-patterns#pattern-1-configure-flows-locally-and-run-end-to-end) or [2](https://developer.incode.com/docs/android-common-implementation-patterns#pattern-2-configure-flows-locally-and-run-step-by-step), adding the module to a `FlowConfig` in code as shown on this page.

## Add Machine Learning Consent

Add the module with `addMachineLearningConsent(machineLearningConsent)`.

```kotlin
flowConfigBuilder.addMachineLearningConsent(machineLearningConsent)
```
```java
flowConfigBuilder.addMachineLearningConsent(machineLearningConsent);
```

### Example

The example below builds a `MachineLearningConsent` module with the US consent variant, adds it to the flow, and listens for the result through `onMachineLearningConsentCompleted()`.

```kotlin
val machineLearningConsent = MachineLearningConsent.Builder()
    .setConsentType(MachineLearningConsent.ConsentType.US)
    .build()

val flowConfig = FlowConfig.Builder()
    .addMachineLearningConsent(machineLearningConsent)
    .build()

val onboardingListener = object : OnboardingListener() {
    override fun onMachineLearningConsentCompleted(result: MachineLearningConsentResult) {
        // Consent step completed. Process the result.
    }
}

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener)
```
```java
MachineLearningConsent machineLearningConsent = new MachineLearningConsent.Builder()
    .setConsentType(MachineLearningConsent.ConsentType.US)
    .build();

FlowConfig flowConfig = new FlowConfig.Builder()
    .addMachineLearningConsent(machineLearningConsent)
    .build();

IncodeWelcome.OnboardingListener onboardingListener = new IncodeWelcome.OnboardingListener() {
    @Override
    public void onMachineLearningConsentCompleted(@NonNull MachineLearningConsentResult result) {
        // Consent step completed. Process the result.
    }
};

IncodeWelcome.getInstance()
    .startOnboarding(activityContext, sessionConfig, flowConfig, onboardingListener);
```

## Configuration Options

Configure the module with `MachineLearningConsent.Builder`. The table below lists the available option.

| Setting                                              | Description                                                                                             |
| ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `setConsentType(MachineLearningConsent.ConsentType)` | Selects the consent text variant: `ConsentType.US` or `ConsentType.GDPR`. Defaults to `ConsentType.US`. |

For the complete option set, see `MachineLearningConsent.Builder` in [API Reference](https://developer.incode.com/docs/android-api-reference).

## Result

Machine Learning Consent delivers a `MachineLearningConsentResult` to the `onMachineLearningConsentCompleted(MachineLearningConsentResult)` callback on the `OnboardingListener`. Key fields include:

- `isSuccess`: `true` if the machine learning consent was submitted successfully; otherwise, `false`.
- Fields inherited from `BaseResult`:
  - `resultCode`: The `ResultCode` for this result.
  - `error`: When `resultCode` is `ERROR`, the `Throwable` that caused it; otherwise, `null`.
  - `deviceStats`: The `DeviceStats` snapshot of the device state when the result was produced.
  - `motionStatus`: Device motion assessment during capture. One of the following:
    - `UNCLEAR`: Motion could not be determined; the default.
    - `PASS`: Device motion was within acceptable limits.
    - `FAIL`: Excessive device motion was detected.

Errors surface through `OnboardingListener.onError(Throwable)`. This module does not define a module-specific exception subtype.

For all fields, see `MachineLearningConsentResult` in [API Reference](https://developer.incode.com/docs/android-api-reference).
