# API

## Usage

The Didomi Android SDK exposes a complete API through the `io.diomi.sdk.Didomi` class. This allows your app to programmatically interact with the Didomi SDK. You can check the user consent status, register consents that you would collect yourself, and show/hide the Didomi UI.

Always use `Didomi.getInstance()` to get a reference to the Didomi SDK. Also make sure to always call the SDK after it is fully initialized (see [onReady](#onready)).

### addEventListener

Add an event listener to catch events triggered by the SDK. [See the dedicated section for more details](https://developers.didomi.io/cmp/mobile-sdk/android/reference/events)

### removeEventListener

Remove a previously add event listener.

**Parameters**

| Name          | Type            | Description                   |
| ------------- | --------------- | ----------------------------- |
| eventListener | `EventListener` | The event listener to remove. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().removeEventListener(currentEventListener);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().removeEventListener(currentEventListener)
```

{% endtab %}
{% endtabs %}

### getDeviceType

Get the device determined by Didomi SDK (mobile or TV).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type         | Description                                                                                                                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DeviceType` | A value of type `DeviceType` reflecting the device type determined at SDK initialization. Can be either `Mobile` (phone or tablet) or `ConnectedTv` (Android TV, Fire TV) |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getDeviceType();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().deviceType
```

{% endtab %}
{% endtabs %}

### getJavaScriptForWebView

Get JavaScript to embed into a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.

Inject the returned tag into a WebView with `evaluateJavaScript`.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type     | Description                           |
| -------- | ------------------------------------- |
| `String` | JavaScript code to embed in a WebView |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getJavaScriptForWebView();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getJavaScriptForWebView()
```

{% endtab %}
{% endtabs %}

### getQueryStringForWebView

Get a query string parameter to append to the URL of a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebView.

Read our article on [sharing consent with WebViews](https://developers.didomi.io/cmp/mobile-sdk/share-consent-with-webviews) for more information.

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type     | Description                                                                                                                                                                            |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `String` | Query string parameter with the format `didomiConfig.user.externalConsent.value=...`. It can be appended to your URL after a `?` or a `&` if your URL already contains a query string. |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getQueryStringForWebView();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().queryStringForWebView
```

{% endtab %}
{% endtabs %}

### hideNotice

Hide the consent notice.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().hideNotice();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().hideNotice()
```

{% endtab %}
{% endtabs %}

### hidePreferences

Hide the preferences popup.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().hidePreferences();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().hidePreferences()
```

{% endtab %}
{% endtabs %}

### initialize

Initialize the SDK. The initialization runs on a background thread to avoid blocking your UI. Use the [onReady](#onready) function to know when the initialization is done and the SDK is ready to be used.

**Parameter:**

<table data-header-hidden><thead><tr><th width="319">Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>Name</td><td>Type</td><td>Description</td></tr><tr><td>application</td><td>Application</td><td>A reference to your Application.</td></tr><tr><td>parameters</td><td>DidomiInitializationParameters</td><td>Object containing the application parameters, see below</td></tr></tbody></table>

The **DidomiInitializationParameters** object contains all the information needed to initialize the SDK.

{% hint style="warning" %}
The parameter `disableDidomiRemoteConfig` is deprecated, we strongly suggest you to create your notice from the console (see [Setup from the Console](https://developers.didomi.io/cmp/mobile-sdk/setup#from-the-console-recommended) for more information).
{% endhint %}

| Parameter                              | Type    | Nullable | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| -------------------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| apiKey                                 | String  | No       | Your API key                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| localConfigurationPath                 | String  | Yes      | The path to your local config file in your `assets/` folder. Defaults to `didomi_config.json` if null.                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| remoteConfigurationPath                | String  | Yes      | The URL to a remote configuration file to load during initialization. When provided, the file at the URL will be downloaded and cached to be used instead of the local `assets/didomi_config.json`. If there is no Internet connection available and no previously cached file, the local file will be used as fallback.                                                                                                                                                                                                                                                 |
| providerId                             | String  | Yes      | Your provider ID (if any). A provider ID is assigned when you work with Didomi through a third-party. If are not sure if you have one, set this to `null`.                                                                                                                                                                                                                                                                                                                                                                                                               |
| disableDidomiRemoteConfig (deprecated) | Boolean | No       | <p>Prevent the SDK from loading a remote configuration from the Didomi Console. Defaults to <code>false</code> (allows loading of remote config).</p><p>Set this parameter to <code>false</code> to use a remote consent notice configuration loaded from the Didomi Console.</p><p>Set this parameter to <code>true</code> to disable loading configurations from the Didomi Console.</p>                                                                                                                                                                               |
| languageCode                           | String  | Yes      | Language in which the consent UI should be displayed. By default, the consent UI is displayed in the language configured in the device settings. This property allows you to override the default setting and specify a language to display the UI in. String containing the language code or the local code e.g.: `"es"`, `"fr"`, `"en-US"`*,* `"zh-HK"`, etc.                                                                                                                                                                                                          |
| noticeId                               | String  | Yes      | Notice ID to load the configuration from. If provided, the SDK bypasses the app ID targeting and directly loads the configuration from the notice ID.                                                                                                                                                                                                                                                                                                                                                                                                                    |
| tvNoticeId                             | String  | Yes      | TV notice ID to load the configuration from. If provided and SDK is initialized on TV, the SDK bypasses the app ID targeting and directly loads the configuration from the notice ID.                                                                                                                                                                                                                                                                                                                                                                                    |
| androidTvEnabled                       | Boolean | No       | <p>Enable the Android TV SDK. Defaults to <code>false</code> (Android TV is not enabled).</p><p>This parameter will be checked if sdk is initialized from a TV device.</p><p>If set to <code>false</code>, the sdk initialization will fail with an error.</p><p>If set to <code>true</code>, the sdk will try to initialize in TV mode, using the API key and the optional <code>tvNoticeId</code> parameter.</p><p>Please note that the TV notice option must be enabled on Didomi side. Please reach out to your dedicated customer success manager to know more.</p> |
| countryCode                            | String  | Yes      | <p>Override user country code when determining the privacy regulation to apply.</p><p>Keep <code>null</code> to let the Didomi SDK determine the user country.</p>                                                                                                                                                                                                                                                                                                                                                                                                       |
| regionCode                             | String  | Yes      | <p>Override user region code when determining the privacy regulation to apply.</p><p>Keep <code>null</code> to let the Didomi SDK determine the user region.</p><p>Ignored if <code>countryCode</code> is not set.</p>                                                                                                                                                                                                                                                                                                                                                   |
| isUnderage                             | Boolean | Yes      | Whether the user is underage or not. This parameters can only be used if the Underage feature has been configured in your notice. (Underage is currently in beta version).                                                                                                                                                                                                                                                                                                                                                                                               |

{% hint style="info" %}
The `initialize` methods with parameters arguments are removed since version 2.0.0, please use `DidomiInitializeParameters` object instead.
{% endhint %}

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().initialize(
    this,
    new DidomiInitializeParameters(
        "<Your API key>",
        null,
        null,
        null,
        false,
        null,
        "<Your notice id>",
        "<Your TV notice id>",
        true
    )
);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
didomi.initialize(
    this,
    DidomiInitializeParameters(
        "<Your API key>",
        noticeId = "<Your notice id>",
        tvNoticeId = "<Your TV notice id>",
        androidTvEnabled = true)
    )
)
```

{% endtab %}
{% endtabs %}

### isNoticeVisible

Check if the consent notice is currently displayed.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

`boolean`

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().isNoticeVisible();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().isNoticeVisible
```

{% endtab %}
{% endtabs %}

### isPreferencesVisible

Check if the preferences popup is currently displayed.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

`boolean`

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().isPreferencesVisible();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().isPreferencesVisible
```

{% endtab %}
{% endtabs %}

### isError

Check if the SDK has encountered an error

**Parameters**

No parameters

**Returns**

`boolean`

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().isError();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().isError
```

{% endtab %}
{% endtabs %}

### isReady

Check if the SDK is ready.

**Parameters**

No parameter.

**Returns**

`boolean`

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().isReady();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().isReady
```

{% endtab %}
{% endtabs %}

### onError

Add an event listener that will be called when the SDK initialization encounters an error. If the event listener is added after the SDK initialization already failed, the listener will be called immediately.

If this listener is called, the SDK initialization will not complete and onReady will not be called.

**Parameters**

| **Name** | Type       | Description                                                                    |
| -------- | ---------- | ------------------------------------------------------------------------------ |
| callback | `Runnable` | An instance of Runnable to run when the SDK initialization encounters an error |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().onError(() -> {
    // The SDK has encountered an error
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().onError {
    // The SDK has encountered an error
}
```

{% endtab %}
{% endtabs %}

### onReady

Add an event listener that will be called when the SDK is ready (ie fully initialized). If the event listener is added after the SDK initialization, the listener will be called immediately.

All calls to other functions of this API must only be made in a listener to the ready event to make sure that the SDK is initialized before it is used.

**Parameters**

| Name     | Type       | Description                                          |
| -------- | ---------- | ---------------------------------------------------- |
| callback | `Runnable` | An instance of Runnable to run when the SDK is ready |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().onReady(() -> {
    // The SDK is ready
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().onReady {
    // The SDK is ready
}
```

{% endtab %}
{% endtabs %}

### openCurrentUserStatusTransaction

**Definition**

Create an instance of the `CurrentUserStatusTransaction` class.

This class provides mechanisms to stage updates to the user status regarding purposes and vendors, allowing for batch operations.

Updates made through its methods are queued and applied simultaneously to the user status only once the `commit` method of the returned object is called.

Additional details:

* The status of vendors and purposes whose IDs are not not specified through the methods provided by `CurrentUserStatusTransaction` are kept unchanged.
* Essential purposes are always set to enabled and can’t be updated by the methods provided by `CurrentUserStatusTransaction`.
* When the regulation applied for a user is `none`, the methods provided by `CurrentUserStatusTransaction` should not update the status of any vendor or purpose which will always remain as enabled. When the `commit` method is called it will return `false`.
* If the IDs that are passed through the methods provided by `CurrentUserStatusTransaction` don’t correspond to vendors or purposes required by the Notice Config, they will be ignored.

**Requires SDK to be initialized**

Yes.

#### Parameters

No parameter.

**Returns**

An instance of the `CurrentUserStatusTransaction` class.

**Description of the** `CurrentUserStatusTransaction` **class**

<table><thead><tr><th width="207">Method</th><th width="233">Parameters</th><th>Returns</th><th>Description</th></tr></thead><tbody><tr><td><code>enablePurpose</code></td><td><code>id</code> (<code>String</code>): ID of the purpose to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable a single purpose based on its ID.</td></tr><tr><td><code>enablePurposes</code></td><td><code>ids</code> (<code>Array&#x3C;String></code>): IDs of the purposes to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable multiple purposes based on their IDs.</td></tr><tr><td><code>disablePurpose</code></td><td><code>id</code> (<code>String</code>): ID of the purpose to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable a single purpose based on its ID.</td></tr><tr><td><code>disablePurposes</code></td><td><code>ids</code> (<code>Array&#x3C;String></code>): IDs of the purposes to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable multiple purposes based on their IDs.</td></tr><tr><td><code>enableVendor</code></td><td><code>id</code> (<code>String</code>): Didomi ID of the vendor to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable a single vendor based on its Didomi ID.</td></tr><tr><td><code>enableVendors</code></td><td><code>ids</code> (<code>Array&#x3C;String></code>): Didomi IDs of the vendors to be enabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Enable multiple vendors based on their Didomi IDs.</td></tr><tr><td><code>disableVendor</code></td><td><code>id</code> (<code>String</code>): Didomi ID of the vendor to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable a single vendor based on its Didomi ID.</td></tr><tr><td><code>disableVendors</code></td><td><code>ids</code> (<code>Array&#x3C;String></code>): Didomi IDs of the vendors to be disabled.</td><td>Current <code>CurrentUserStatusTransaction</code> object.</td><td>Disable multiple vendors based on their Didomi IDs.</td></tr><tr><td><code>commit</code></td><td>No parameters.</td><td><code>Boolean</code>: <code>true</code> if user status has been updated, <code>false</code> otherwise.</td><td>Commit the changes that have been made through other methods.</td></tr></tbody></table>

#### Examples

{% tabs %}
{% tab title="Kotlin" %}

<pre class="language-kotlin"><code class="lang-kotlin"><strong>val didomi = Didomi.getInstance()
</strong>val transaction = didomi.openCurrentUserStatusTransaction()

// Enable a purpose
transaction.enablePurpose("cookies")
// Enable purposes
transaction.enablePurposes("cookies", "analytics")
// Disable a purpose
transaction.disablePurpose("analytics")
// Disable purposes
transaction.disablePurposes("cookies", "analytics")
// Enable a vendor
transaction.enableVendor("vendor-1")
// Enable vendors
transaction.enableVendors("vendor-1", "vendor-2")
// Disable a vendor
transaction.disableVendor("vendor-1")
// Disable vendors
transaction.disableVendors("vendor-1", "vendor-2")

// Chain multiple calls
transaction.enablePurpose("cookies").disablePurpose("analytics")

// Save user choices
val updated = transaction.commit()
</code></pre>

{% endtab %}

{% tab title="Java" %}

```java
Didomi didomi = Didomi.getInstance();
CurrentUserStatusTransaction transaction = didomi.openCurrentUserStatusTransaction();

// Enable a purpose
transaction.enablePurpose("cookies");
// Enable purposes
transaction.enablePurposes(Arrays.asList("cookies", "analytics"));
// Disable a purpose
transaction.disablePurpose("analytics");
// Disable purposes
transaction.disablePurposes(Arrays.asList("cookies", "analytics"));
// Enable a vendor
transaction.enableVendor("vendor-1");
// Enable vendors
transaction.enableVendors(Arrays.asList("vendor-1", "vendor-2"));
// Disable a vendor
transaction.disableVendor("vendor-1");
// Disable vendors
transaction.disableVendors(Arrays.asList("vendor-1", "vendor-2"));

// Chain multiple calls
transaction.enablePurpose("cookies").disablePurpose("analytics");

// Save user choices
boolean updated = transaction.commit();
```

{% endtab %}
{% endtabs %}

### setLogLevel

Set the minimum level of messages to log. The SDK will not log messages under that level.\
See [Logging](https://developers.didomi.io/cmp/mobile-sdk/android/logging) for more information.

**Parameters**

| Name     | Type  | Description                       |
| -------- | ----- | --------------------------------- |
| minLevel | `int` | Minimum level of messages to log. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().setLogLevel(android.util.Log.INFO);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().setLogLevel(android.util.Log.INFO)
```

{% endtab %}
{% endtabs %}

### setupUI

Setup the SDK UI. By calling this method, the consent notice will be displayed once the SDK is ready and if consent should be collected. It does not show any view if consent was already collected or is not required.\
This method should be called in the `onCreate` function of your activities and should be called in every activity where consent can be collected.

**Parameters**

| Name     | Type               | Description                                                                      |
| -------- | ------------------ | -------------------------------------------------------------------------------- |
| activity | `FragmentActivity` | Activity used to get the Support Fragment Manager to display the consent notice. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().setupUI(this);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().setupUI(this)
```

{% endtab %}
{% endtabs %}

### showNotice

{% hint style="info" %}
In most cases this method should be called if the notice should be displayed in response to a user action (e.g.: select the privacy settings section within your app). By calling the setupUI method, the notice will be automatically displayed if required.
{% endhint %}

Show the consent notice. The consent notice actually only gets shown if needed (consent is required and we are missing consent information for some vendor or purpose).

**Parameters**

| Type             |                                                                                    |
| ---------------- | ---------------------------------------------------------------------------------- |
| FragmentActivity | Activity used to get the Support Fragment Manager to display the Preferences view. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().showNotice();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().showNotice()
```

{% endtab %}
{% endtabs %}

### showPreferences

{% hint style="info" %}
In most cases this method should be called if you want to show the Preferences screen in response to a user action (the user pressing a "Consent Preferences" button in your app menu, for instance).
{% endhint %}

Show the Preferences view to the user. This method can be used to allow the user to update their preferences after the banner has been closed. We suggest adding a link/button/item that calls this method somewhere in your app, for example from your settings menu. By default, the Purposes view is displayed first. By calling this method, users will have the opportunity to modify the choices previously made.

**Parameters**

| Type              |                                                                                                                                                                                                                                                                                                                                             |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| FragmentActivity  | Activity used to get the Support Fragment Manager to display the Preferences view.                                                                                                                                                                                                                                                          |
| String (Optional) | Defines which view is displayed to the user first between the purposes view or the vendors view. We expose the values to provide on the Didomi class as `VIEW_PURPOSES`, `VIEW_VENDORS` and `VIEW_SENSITIVE_PERSONAL_INFORMATION`. If this parameter is not defined or contains an unexpected string, the purposes' view will be displayed. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
// We pass "this" as a parameter as this method is called from an Activity.
Didomi.getInstance().showPreferences(this);
Didomi.getInstance().showPreferences(this, Didomi.VIEW_PURPOSES);
Didomi.getInstance().showPreferences(this, Didomi.VIEW_VENDORS);
Didomi.getInstance().showPreferences(this, Didomi.VIEW_SENSITIVE_PERSONAL_INFORMATION);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// We pass "this" as a parameter as this method is called from an Activity.
Didomi.getInstance().showPreferences(activity = this)
Didomi.getInstance().showPreferences(activity = this, view = Didomi.VIEW_PURPOSES)
Didomi.getInstance().showPreferences(activity = this, view = Didomi.VIEW_VENDORS)
Didomi.getInstance().showPreferences(activity = this, view = Didomi.VIEW_SENSITIVE_PERSONAL_INFORMATION)
```

{% endtab %}
{% endtabs %}

### updateSelectedLanguage

Method used to update the selected language of the Didomi SDK and any property that depends on it.

In most cases this method doesn't need to be called. It would only be required for those apps that allow language change on-the-fly, i.e.: from within the app rather than from the device settings.

If your configuration involves country code (`en-US`), you can provide a locale code to change the regional configuration as well. If only language code (`en`) is provided and your configuration requires a country code, the country from the device location will be used (and will fallback to the default country if required).

In order to update the language of the views displayed by the Didomi SDK, this method needs to be called before these views are displayed.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name         | Type     | Description                                                                                                        |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------ |
| languageCode | `String` | string containing the 2-letter language code or 5-letter locale code e.g. `en`, `es`, `fr`, `en-US`, `zh-HK`, etc. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().onReady(() -> {
    Didomi.getInstance().updateSelectedLanguage("fr");
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().onReady {
    Didomi.getInstance().updateSelectedLanguage("fr")
}
```

{% endtab %}
{% endtabs %}

***

## Notice Config

### getPurpose

Get a purpose based on its ID.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name      | Type     | Description                       |
| --------- | -------- | --------------------------------- |
| purposeId | `String` | ID of the purpose we want to get. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type      | Description                                                              |
| --------- | ------------------------------------------------------------------------ |
| `Purpose` | A `Purpose` with ID `purposeId` found in the array of required purposes. |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getPurpose("purpose-id");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getPurpose("purpose-id")
```

{% endtab %}
{% endtabs %}

### getRequiredPurposes

Get the list of purpose that are required (automatically determined from the list of required vendors).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type           | Description                                               |
| -------------- | --------------------------------------------------------- |
| `Set<Purpose>` | A set of type `Purpose` containing the required purposes. |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getRequiredPurposes();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().requiredPurposes
```

{% endtab %}
{% endtabs %}

### getRequiredVendors

Get the list of vendors that are required (determined from the configuration).

**Requires SDK to be initialized**

Yes.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type          | Description                                             |
| ------------- | ------------------------------------------------------- |
| `Set<Vendor>` | A set of type `Vendor` containing the required vendors. |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getRequiredVendors();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().requiredVendors
```

{% endtab %}
{% endtabs %}

### getText

Method used to get a dictionary/map based on the key being passed. These keys and texts are extracted from the notice content, preferences content and the `texts` property specified in the `didomi_config.json` file as described here <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-theme#translatable-texts-for-custom-notices>.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name | Type   | Description                                           |
| ---- | ------ | ----------------------------------------------------- |
| key  | String | key associated to the dictionary that we want to get. |

**Throws**

<table data-header-hidden><thead><tr><th width="495">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Type</strong></td><td>Description</td></tr><tr><td>DidomiNotReadyException</td><td>Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the <code>onReady</code> method.</td></tr></tbody></table>

**Returns**

| Type           | Description                                                                                                                                                 |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Dictionary/map | Dictionary/map containing the translations for an specific key in different languages, with the form { "en:" "text in English", "fr": "texte en Français" } |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getText("key");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getText("key")
```

{% endtab %}
{% endtabs %}

### getTranslatedText

Method used to get a translated text based on the key being passed.

The language and the source of this translated text will depend on the availability of the translation for the specific key.

The language being used will be either the selected language of the SDK (based on device Locale and other parameters) or the language specified by app developers as the default language being used by the SDK. The source can be either the `didomi_config.json` file, which can be either local or remote, or a file that is bundled within the SDK.

These are the attempts performed by the SDK to try to find a translation for the specific key:

* Get translated value in user locale (selected language) from `didomi_config.json` (either local or remote).
* Get translated value in default locale (from the config) from `didomi_config.json` (either local or remote).
* Get translated value in user locale (selected language) from the Didomi-provided translations (bundled within the Didomi SDK).
* Get translated value in default locale (from the config) from the Didomi-provided translations (bundled within the Didomi SDK).

If no translation can be found after these 4 attempts, the key will be returned.

App developers can provide these translated texts through the `didomi_config.json` file (locally or remotely) in 3 different ways:

* Custom texts for the consent notice: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-notice#texts>
* Custom texts for the preferences: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/customize-the-preferences-popup#text>
* Custom texts for custom notices: <https://developers.didomi.io/cmp/mobile-sdk/consent-notice/build-your-own-custom-notice#translatable-texts-for-custom-notices>

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name | Type   | Description                                                |
| ---- | ------ | ---------------------------------------------------------- |
| key  | String | key associated to the text that we want to get translated. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Translated text.

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getTranslatedText("key");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getTranslatedText("key")
```

{% endtab %}
{% endtabs %}

### getVendor

Get a vendor based on its ID.

**Requires SDK to be initialized**

Yes.

**Parameters**

| Name     | Type     | Description                      |
| -------- | -------- | -------------------------------- |
| vendorId | `String` | ID of the vendor we want to get. |

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type     | Description                                                           |
| -------- | --------------------------------------------------------------------- |
| `Vendor` | A `Vendor` with ID `vendorId` found in the array of required vendors. |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getVendor("vendor-id");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getVendor("vendor-id")
```

{% endtab %}
{% endtabs %}

### getTotalVendorCount

Get the count of required vendors.

**Requires SDK to be initialized**

Yes.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type  | Description            |
| ----- | ---------------------- |
| `Int` | The total vendor count |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getTotalVendorCount();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getTotalVendorCount()
```

{% endtab %}
{% endtabs %}

### getIabVendorCount

Get the count of required IAB vendors.

**Requires SDK to be initialized**

Yes.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type  | Description          |
| ----- | -------------------- |
| `Int` | The IAB vendor count |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getIabVendorCount();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getIabVendorCount()
```

{% endtab %}
{% endtabs %}

### getNonIabVendorCount

Get the count of required vendors which are not part of the IAB.

**Requires SDK to be initialized**

Yes.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

| Type  | Description              |
| ----- | ------------------------ |
| `Int` | The non-IAB vendor count |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().getNonIabVendorCount();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().getNonIabVendorCount()
```

{% endtab %}
{% endtabs %}

***

## User Status

### applicableRegulation

Get the applicable regulation.

**Requires SDK to be initialized**

**yes.**

**Returns**

| Type     | Description                                                                                                                                                                                                                                                      |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `String` | <p>Representation of the current regulation as a <code>Regulation</code> String value, such as <code>GDPR</code>, <code>CCPA</code>, <code>CPRA</code>, or <code>NONE</code>.</p><p>Note that some regulations present as enum values are not available yet.</p> |

**Example**

{% tabs %}
{% tab title="Java" %}

```java
String regulation = Didomi.getInstance().getApplicableRegulation();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val regulation = Didomi.getInstance().applicableRegulation
```

{% endtab %}
{% endtabs %}

### addVendorStatusListener

Listen for changes on the user status linked to a specific vendor.

**Requires SDK to be initialized**

No.

**Parameters**

| Name     | Type                                                 | Description                                                                                                                                                          |
| -------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id       | `String`                                             | <p>The ID of the vendor for which we want to start listening for changes.</p><p><br>This ID should be the ID provided by Didomi, which doesn't contain prefixes.</p> |
| callback | callback: `(CurrentUserStatus.VendorStatus) -> Unit` | Callback that will be executed whenever changes are detected on the specified vendor.                                                                                |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().addVendorStatusListener("vendor-id", (newStatus) -> {
    System.out.println("Vendor Status changed. New status: " + newStatus);
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().addVendorStatusListener("vendor-id") { newStatus ->
    println("Vendor Status changed. New status: $newStatus")
}
```

{% endtab %}
{% endtabs %}

### removeVendorStatusListener

Stop listening for changes on the user status linked to a specific vendor.

**Requires SDK to be initialized**

No.

**Parameters**

| Name | Type     | Description                                                                                                                                                     |
| ---- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id   | `String` | <p>The ID of the vendor for which we want to stop listening for changes.</p><p>This ID should be the ID provided by Didomi, which doesn't contain prefixes.</p> |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().removeVendorStatusListener("vendor-id");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().removeVendorStatusListener("vendor-id")
```

{% endtab %}
{% endtabs %}

### getCurrentUserStatus

#### Definition

Exposes the user status for the current regulation that applies.

#### Parameters

No parameters.

#### Returns

The user status containing the computed global status for Vendors and purposes:

* A vendor's global status is enabled, if and only if:
  * the vendor is enabled directly in the vendors layer in all legal basis
  * **AND** all its related purposes are enabled or essential.
* A purpose's global status is enabled in one of the two conditions:
  * the purpose is enabled for all the legal basis that it is configured for.
  * **OR** when the purpose is essential.

| Parameter                     | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ----------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| didomi\_dcs                   | `string` | Didomi Consent String that stores end-user choices for custom and Google ATP vendors, and custom and global purposes across all regulations. [Click here](https://developers.didomi.io/cmp/didomi-consent-string) for more information.                                                                                                                                                                                                 |
| vendors                       | `object` | <ul><li>Dictionary that maps the ID of a vendor to an object representing its status.</li><li>The IDs used in this dictionary correspond to the Didomi IDs i.e.: without the <code>c:</code> or any other prefix.</li><li>Vendors with undefined user status are included in the response with <code>enabled: false.</code></li><li>Vendors with ONLY essential purposes are automatically set with <code>enable: true</code></li></ul> |
| purposes                      | `object` | <ul><li>Dictionary that maps the ID of a purpose to an object representing its status.</li><li>Purposes with undefined user status are included in the response with <code>enabled: false.</code></li><li>Essential purposes are automatically set with <code>enable: true</code></li></ul>                                                                                                                                             |
| regulation                    | `String` | <ul><li>Representation of the current regulation as a <code>Regulation</code> enum value, such as <code>GDPR</code>, <code>CCPA</code>, <code>CPRA</code>, or <code>NONE</code>.</li><li>Note that some regulations present as enum values are not available yet.</li></ul>                                                                                                                                                             |
| userId                        | `String` | Didomi user id.                                                                                                                                                                                                                                                                                                                                                                                                                         |
| created                       | `String` | User choices creation date.                                                                                                                                                                                                                                                                                                                                                                                                             |
| updated                       | `String` | User choices update date.                                                                                                                                                                                                                                                                                                                                                                                                               |
| consentString                 | `String` | TCF consent as string                                                                                                                                                                                                                                                                                                                                                                                                                   |
| additionalConsent             | `String` | Additional consent.                                                                                                                                                                                                                                                                                                                                                                                                                     |
| gppString                     | `String` | GPP string.                                                                                                                                                                                                                                                                                                                                                                                                                             |
| shouldUserStatusBeCollected() | `Bool`   | Determine if the User Status (consent) should be collected or not, based on regulation, expiration date, and user status at the time of the call to `Didomi#getCurrentUserStatus()`. This method is only valid for objects returned by Didomi after a call to `getCurrentUserStatus()`.                                                                                                                                                 |

#### **Throws**

<table data-header-hidden><thead><tr><th width="334">Type</th><th>Description</th></tr></thead><tbody><tr><td><strong>Type</strong></td><td>Description</td></tr><tr><td>DidomiNotReadyException</td><td>Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the <code>onReady</code> method.</td></tr></tbody></table>

#### Examples

{% tabs %}
{% tab title="Java" %}

```java
CurrentUserStatus currentUserStatus = Didomi.getInstance().getCurrentUserStatus();

// Example: get consent status for vendor `google`
VendorStatus vendorStatus = currentUserStatus.vendors["google"];
bool isVendorEnabled = vendorStatus.enabled;

// Example: get consent status for custom vendor
// with ID `custom-vendor-id` (without `c:` prefix).
VendorStatus customVendorStatus = currentUserStatus.vendors["custom-vendor-id"];
bool isCustomVendorEnabled = customVendorStatus.enabled;
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val currentUserStatus = Didomi.getInstance().currentUserStatus

// Example: get consent status for vendor `google`
val vendorStatus = currentUserStatus.vendors["google"]
val isVendorEnabled = vendorStatus.enabled
```

{% endtab %}
{% endtabs %}

### isUserStatusPartial

#### Definition

Determine if the user has provided a choice for all vendors selected for the regulation and linked data processing.

This function returns `true` if the user has not expressed a choice for all the required vendors and data processing.

Requires SDK to be initialized.

#### Parameters

No parameters.

#### Returns

`boolean`

* This function returns true if the following conditions are all met
  * A regulation apply for the current user (i.e: regulation is not NONE)
  * At least one vendor is configured (if there is no vendor configured, this function always returns false as there is no status to collect)
  * We miss user status for some vendors or purposes
* Otherwise, it will return false.
  * e.g: If regulation = none (i.e no regulation apply to the end user) → This function returns false
* Edge cases: a new vendor is added to the notice and status is not collected yet for that vendor. In this case the function will return true until the user update their choice on the consent banner.

#### Throws (Android and Flutter only)

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

#### Examples

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().isUserStatusPartial();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().isUserStatusPartial
```

{% endtab %}
{% endtabs %}

### setCurrentUserStatus

#### Definition

Set the user status for purposes and vendors. This function will trigger events and API calls every time it is called (and the user status changes) so make sure to push all user choices at once and not one by one.

Please read [our article](https://support.didomi.io/analytics-with-a-custom-setup) on what to expect from your analytics when setting a custom behavior for your consent notice.

#### Parameters

Add the desired global status for each vendor and each purpose:

* the vendor status specified in this function will be reflected on the vendor’s layer.
  * vendor enabled : true → means the vendor is enabled in all the legal basis that this vendor uses.
  * vendor enabled : false → means the vendor is disabled in all the legal basis that this vendor uses
* the purposes status specified in this function will be reflected on the preferences layer.
  * purpose enabled : true → means the purpose is enabled in all the legal basis in which it’s defined.
  * purpose enabled : false → means the purpose is disabled in all the legal basis in which it’s defined.

#### Returns

`boolean`

`true` if the user choices have changed (i.e. the user had made different choices before this function got called).

#### Throws (Android and Flutter only)

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

#### Examples

{% tabs %}
{% tab title="Java" %}

```java
Map<String, PurposeStatus> purposes = new HashMap<>();
purposes.put("purpose1", new PurposeStatus("purpose1", true));

Map<String, VendorStatus> vendors = new HashMap<>();
vendors.put("vendor1", new VendorStatus("vendor1", true));

CurrentUserStatus currentUserStatus = new CurrentUserStatus(purposes, vendors);
 
boolean updated = Didomi.getInstance().setCurrentUserStatus(currentUserStatus);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val currentUserStatus = CurrentUserStatus(
    purposes = mapOf("purpose1" to CurrentUserStatus.PurposeStatus(id = "purpose1", enabled = true)),
    vendors = mapOf("vendor1" to CurrentUserStatus.VendorStatus(id = "vendor1", enabled = true)),
)

val updated = Didomi.getInstance().setCurrentUserStatus(currentUserStatus)
```

{% endtab %}
{% endtabs %}

### reset

Reset all the consent information for the current user. This will remove all consent information stored on the device by Didomi and will trigger re-collection of consent. The consent notice will be displayed again when `setupUI` is called.

If the SDK is not initialized when this method is called, the reset will be performed during SDK initialization.

**Parameters**

No parameter.

**Throws**

Nothing

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().reset();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().reset()
```

{% endtab %}
{% endtabs %}

### setUserAgreeToAll

Report that the user has enabled consents and legitimate interests for all purposes and vendors configured for your app.

This function will log the user choice on our platform and close the notice.

Consent statuses for essential purposes are not stored.

Please read [our article](https://support.didomi.io/analytics-with-a-custom-setup) on what to expect from your analytics when setting a custom behavior for your consent notice.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

`boolean`

`true` if the user choices have changed (i.e. the user had made different choices before this function got called).

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().setUserAgreeToAll();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().setUserAgreeToAll()
```

{% endtab %}
{% endtabs %}

### setUserDisagreeToAll

Report that the user has disabled consents and legitimate interests for all purposes and vendors configured for your app.

This function will log the user choice on our platform and close the notice.

Consent statuses for essential purposes are not stored.

Please read [our article](https://support.didomi.io/analytics-with-a-custom-setup) on what to expect from your analytics when setting a custom behavior for your consent notice.

**Parameters**

No parameter.

**Throws**

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

`boolean`

`true` if the user choices have changed (i.e. the user had made different choices before this function got called).

**Example**

{% tabs %}
{% tab title="Java" %}

```javascript
Didomi.getInstance().setUserDisagreeToAll();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().setUserDisagreeToAll()
```

{% endtab %}
{% endtabs %}

### shouldUserStatusBeCollected

#### Definition

Determine if user status (consent) should be collected for the visitor. Returns `true` if user status is required for the current user and one of following two conditions is met:

* User status has never been collected for this visitor yet
* New user status should be collected (as new vendors have been added) AND the number of days before recollecting them has exceeded

If none of these two conditions is met, the function returns `false`. This function is mainly present to allow you to know when to display your own notice if you have disabled our standard notice.

Requires SDK to be initialized.

#### **Parameters**

No parameter.

#### **Returns**

`boolean`

#### Throws (Android and Flutter only)

| **Type**                | Description                                                                                                                                                                                                       |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| DidomiNotReadyException | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

#### Examples

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().shouldUserStatusBeCollected();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().shouldUserStatusBeCollected()
```

{% endtab %}
{% endtabs %}

### setUser

The `setUser` function is used to configure settings specific to the user currently navigating the mobile app. It can be used in various scenarios, such as:

* Authenticating the user.
* Enabling cross-device functionality. For detailed information, see [documentation](https://developers.didomi.io/cmp/mobile-sdk/share-consents-across-devices).
* Setting user-specific attributes, like identifying the user as underage.

**Parameter:**

<table><thead><tr><th width="198">Name</th><th width="254">Type</th><th>Description</th></tr></thead><tbody><tr><td>parameters</td><td><code>DidomiUserParameters</code></td><td>Object containing properties required to set a user.</td></tr></tbody></table>

***Description for*** `DidomiUserParameters`***:***

<table><thead><tr><th width="193">Name</th><th width="219">Type</th><th>Description</th></tr></thead><tbody><tr><td>userAuth</td><td><code>UserAuth</code></td><td>User authentication object. Can be either <code>UserAuthWithoutParams</code>, <code>UserAuthWithEncryptionParams</code> or <code>UserAuthWithHashParams</code>.</td></tr><tr><td>dcsUserAuth</td><td><code>UserAuthParams?</code></td><td>Optional. Dedicated user with encryption or hash used for Didomi Consent String signature. Can be either <code>UserAuthWithEncryptionParams</code> or <code>UserAuthWithHashParams</code>.<br>This parameter can only be used if you are using the Didomi Consent String feature (This feature is currently in beta version)</td></tr><tr><td>activity</td><td><code>FragmentActivity?</code></td><td>Optional. Activity of the application if the notice should be displayed when the consent expired or the user is new.</td></tr><tr><td>isUnderage</td><td><code>Boolean?</code></td><td>Optional. Whether the user is underage or not. This parameters can only be used if the Underage feature has been configured in your notice. (Underage is currently in beta version).</td></tr></tbody></table>

Parameters for `UserAuthWithoutParams` :

<table><thead><tr><th width="204">Name</th><th width="228">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>String</code></td><td>Organization ID to associate with the user.</td></tr></tbody></table>

Parameters for `UserAuthWithEncryptionParams` :

<table><thead><tr><th width="211">Name</th><th width="202">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>String</code></td><td>Organization ID to associate with the user.</td></tr><tr><td>algorithm</td><td><code>String</code></td><td>Algorithm used for computing the user ID.</td></tr><tr><td>secretId</td><td><code>String</code></td><td>ID of the secret used for the computing the user ID.</td></tr><tr><td>initializationVector</td><td><code>String</code></td><td>Initialization Vector used for encrypting the message.</td></tr><tr><td>expiration</td><td><code>Long?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0).</td></tr></tbody></table>

Parameters for `UserAuthWithHashParams` :

<table><thead><tr><th width="212">Name</th><th width="205">Type</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td><code>String</code></td><td>Organization ID to associate with the user.</td></tr><tr><td>algorithm</td><td><code>String</code></td><td>Algorithm used for computing the user ID.</td></tr><tr><td>secretId</td><td><code>String</code></td><td>ID of the secret used for the computing the user ID.</td></tr><tr><td>digest</td><td><code>String</code></td><td>Digest used for representing the user ID</td></tr><tr><td>salt</td><td><code>String?</code></td><td>Optional. Salt used for computing the user ID.</td></tr><tr><td>expiration</td><td><code>Long?</code></td><td>Optional. Expiration time as UNIX timestamp (must be > 0)</td></tr></tbody></table>

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().setUser(new DidomiUserParameters(
            new UserAuthWithoutParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a"
            ), // user ID
            new UserAuthWithEncryptionParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
                        "algorithm",
                        "secret_id",
                        "initialization_vector",
                        10000L // or null
            ), // optional DCS user authentication
            activity, // optional activity
            true // optional underage flag
));

Didomi.getInstance().setUser(new DidomiUserParameters(
            new UserAuthWithEncryptionParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "initialization_vector",
                        10000L // or null
            ), // user authentication
            new UserAuthWithEncryptionParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
                        "algorithm",
                        "secret_id",
                        "initialization_vector",
                        10000L // or null
            ), // optional DCS user authentication
            activity, // optional activity
            true // optional underage flag
));

Didomi.getInstance().setUser(new DidomiUserParameters(
            new UserAuthWithHashParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
                        "algorithm",
                        "secret_id",
                        "digest",
                        "salt", // or null
                        10000L // or null
            ), // user authentication
            new UserAuthWithHashParams(
                        "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
                        "algorithm",
                        "secret_id",
                        "digest",
                        "salt", // or null
                        10000L // or null
            ), // optional DCS user authentication
            activity, // optional activity
            true // optional underage flag
));
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().setUser(DidomiUserParameters(
    userAuth = UserAuthWithoutParams(
        "e3222031-7c45-4f4a-8851-ffd57dbf0a2a"
    ), // user ID
    dcsUserAuth = UserAuthWithEncryptionParams(
        id = "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
        algorithm = "algorithm",
        secretId = "secret_id",
        initializationVector = "initialization_vector",
        expiration = 10000L // or null
    ), // optional DCS user authentication
    activity = activity, // optional activity
    isUnderage = true, // optional underage flag
))

Didomi.getInstance().setUser(DidomiUserParameters(
    userAuth = UserAuthWithEncryptionParams(
        id = "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
        algorithm = "algorithm",
        secretId = "secret_id",
        initializationVector = "initialization_vector",
        expiration = 10000L // or null
    ), // user authentication
    dcsUserAuth = UserAuthWithEncryptionParams(
        id = "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
        algorithm = "algorithm",
        secretId = "secret_id",
        initializationVector = "initialization_vector",
        expiration = 10000L // or null
    ), // optional DCS user authentication
    activity = activity, // optional activity
    isUnderage = true, // optional underage flag
))

Didomi.getInstance().setUser(DidomiUserParameters(
    userAuth = UserAuthWithHashParams(
        id = "e3222031-7c45-4f4a-8851-ffd57dbf0a2a",
        algorithm = "algorithm",
        secretId = "secret_id",
        digest = "digest",
        salt = "salt", // or null
        expiration = 10000L // or null
    ), // user authentication
    dcsUserAuth = UserAuthWithHashParams(
        id = "e3222031-7c45-4f4a-8851-ffd57dbf0a2b",
        algorithm = "algorithm",
        secretId = "secret_id",
        digest = "digest",
        salt = "salt", // or null
        expiration = 10000L // or null
    ), // optional DCS user authentication
    activity = activity, // optional activity
    isUnderage = true, // optional underage flag
))
```

{% endtab %}
{% endtabs %}

### clearUser

Remove the user information from organization. This will also reset the Didomi User ID.

**Throws**

| **Type**                  | Description                                                                                                                                                                                                       |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DidomiNotReadyException` | Exception thrown when a method that requires the Didomi SDK to be ready is called before that. Developers can call this method within a try/catch or within a lambda expression passed into the `onReady` method. |

**Returns**

Nothing

**Example**

{% tabs %}
{% tab title="Java" %}

```java
Didomi.getInstance().clearUser();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
Didomi.getInstance().clearUser()
```

{% endtab %}
{% endtabs %}
