# User Consent

The User Consent module shows a custom consent agreement for the user to review and accept. Use it to capture an explicit, recorded agreement at a chosen point in the flow. The consent step records acceptance against the current onboarding session; the exact downstream behavior depends on your Incode Flow or Workflow configuration.

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.

{/* PM: True? No Dashboard equivalent? */}

For acceptance of multiple statements on one screen, see [Combined Consent](https://developer.incode.com/docs/android-combined-consent). For biometric or machine learning data consent, see [Machine Learning Consent](https://developer.incode.com/docs/android-machine-learning-consent).

## Add User Consent

1. Add the module with `addUserConsent(userConsent)`.

   ```kotlin
   flowConfigBuilder.addUserConsent(userConsent)
   ```
   ```java
   flowConfigBuilder.addUserConsent(userConsent);
   ```

2) Add any [Approval](https://developer.incode.com/docs/android-approval) or [Results](https://developer.incode.com/docs/android-results) modules after User Consent.

### Example

The example below builds a `UserConsent` module with a title and body, adds it to a `FlowConfig` with a flow tag, and starts an onboarding section.

```kotlin
try {
    val userConsent = UserConsent.Builder()
        .setTitle("Terms and conditions")
        .setContent("I agree to the terms and conditions.")
        .build()

    val flowConfig = FlowConfig.Builder()
        .setFlowTag("User consent section")
        .addUserConsent(userConsent)
        .build()

    IncodeWelcome.getInstance()
        .startOnboardingSection(activityContext, flowConfig, object : OnboardingListener() {
            override fun onUserConsentCompleted() {
                // User accepted the consent
            }

            override fun onError(error: Throwable) {}

            override fun onUserCancelled() {}

            override fun onOnboardingSectionCompleted(flowTag: String) {
                // User consent section complete
            }
        }
    )
} catch (e: ModuleConfigurationException) {
    e.printStackTrace()
}
```
```java
try {
    UserConsent userConsent = new UserConsent.Builder()
        .setTitle("Terms and conditions")
        .setContent("I agree to the terms and conditions.")
        .build();

    FlowConfig flowConfig = new FlowConfig.Builder()
        .setFlowTag("User consent section")
        .addUserConsent(userConsent)
        .build();

    IncodeWelcome.getInstance()
        .startOnboardingSection(activityContext, flowConfig, new IncodeWelcome.OnboardingListener() {
            @Override
            public void onUserConsentCompleted() {
                // User accepted the consent
            }

            @Override
            public void onError(@NonNull Throwable error) {}

            @Override
            public void onUserCancelled() {}

            @Override
            public void onOnboardingSectionCompleted(@NonNull String flowTag) {
                // User consent section complete
            }
        }
    );
} catch (ModuleConfigurationException e) {
    e.printStackTrace();
}
```

## Configuration Options

Configure the module with `UserConsent.Builder`. The table below lists the common options.

| Setting              | Description                                                         |
| -------------------- | ------------------------------------------------------------------- |
| `setTitle(String)`   | Sets the heading shown above the consent body text.                 |
| `setContent(String)` | Sets the consent body text the user reviews and accepts or rejects. |

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

## Result

User Consent does not deliver a result payload to the `OnboardingListener`. The `onUserConsentCompleted()` callback signals that the user accepted the consent. If the user rejects the consent, the `onUserCancelled()` callback fires instead. Any failure surfaces on `onError(Throwable)`.

<br />For the related result type and its fields, see `UserConsentResult` in [API Reference](https://developer.incode.com/docs/android-api-reference).
