Reference - Android

This section is a comprehensive reference of the methods and events exposed by the Android SDK that you can leverage in your application.

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).

addEventListener

Add an event listener to catch events triggered by the SDK. Events listeners allow you to react to different events of interest. This function is safe to call before the ready event has been triggered.

Parameters

Name

Type

Description

eventListener

EventListener

The event listener. An instance of a subclass of io.didomi.sdk.events.EventListener

Returns

Nothing

Example

Java
import io.didomi.sdk.events.ConsentChangedEvent;
import io.didomi.sdk.events.EventListener;
import io.didomi.sdk.events.HideNoticeEvent;
import io.didomi.sdk.events.ShowNoticeEvent;
import io.didomi.sdk.events.NoticeClickAgreeEvent;
import io.didomi.sdk.events.NoticeClickMoreInfoEvent;
import io.didomi.sdk.events.PreferencesClickAgreeToAllEvent;
import io.didomi.sdk.events.PreferencesClickDisagreeToAllEvent;
import io.didomi.sdk.events.PreferencesClickPurposeAgreeEvent;
import io.didomi.sdk.events.PreferencesClickPurposeDisagreeEvent;
import io.didomi.sdk.events.PreferencesClickViewVendorsEvent;
import io.didomi.sdk.events.PreferencesClickSaveChoicesEvent;
import io.didomi.sdk.events.PreferencesClickVendorAgreeEvent;
import io.didomi.sdk.events.PreferencesClickVendorDisagreeEvent;
import io.didomi.sdk.events.PreferencesClickVendorSaveChoicesEvent;
Didomi.getInstance().addEventListener(new EventListener() {
@Override
public void consentChanged(ConsentChangedEvent event) {
// The consent status of the user has changed
}
@Override
public void hideNotice(HideNoticeEvent event) {
// The notice is being hidden
}
@Override
public void showNotice(ShowNoticeEvent event) {
// The notice is being shown
}
@Override
public void noticeClickAgree(NoticeClickAgreeEvent event) {
// Click on agree on notice
}
@Override
public void noticeClickMoreInfo(NoticeClickMoreInfoEvent event) {
// Click on learn more on notice
}
@Override
public void preferencesClickAgreeToAll(PreferencesClickAgreeToAllEvent event) {
// Click on agree to all on preferences popup
}
@Override
public void preferencesClickDisagreeToAll(PreferencesClickDisagreeToAllEvent event) {
// Click on disagree to all on preferences popup
}
@Override
public void preferencesClickPurposeAgree(PreferencesClickPurposeAgreeEvent event) {
String vendorId = event.getPurposeId();
// Click on agree to a purpose on preferences popup
}
@Override
public void preferencesClickPurposeDisagree(PreferencesClickPurposeDisagreeEvent event) {
String vendorId = event.getPurposeId();
// Click on disagree to a purpose on preferences popup
}
@Override
public void preferencesClickViewVendors(PreferencesClickViewVendorsEvent event) {
// Click view vendors on purposes view on preferences popup
}
@Override
public void preferencesClickSaveChoices(PreferencesClickSaveChoicesEvent event) {
// Click on save on the purposes view on preferences popup
}
@Override
public void preferencesClickVendorAgree(PreferencesClickVendorAgreeEvent event) {
String vendorId = event.getVendorId();
// Click on agree to a vendor on preferences popup
}
@Override
public void preferencesClickVendorDisagree(PreferencesClickVendorDisagreeEvent event) {
String vendorId = event.getVendorId();
// Click on disagree to a vendor on preferences popup
}
@Override
public void preferencesClickVendorSaveChoices(PreferencesClickVendorSaveChoicesEvent event) {
// Click on save on the vendors view on preferences popup
}
});

Event types

The following event types are supported by the Didomi SDK:

Method

Event type

Description

consentChanged

ConsentChangedEvent

When a consent is given or withdrawn by the user. Only triggered when the consent status actually changes (ie if the user saves consents without adding/removing any consent then this does not get called).

hideNotice

HideNoticeEvent

When the consent notice is hidden. If you have disabled our default consent notice to replace it with your own, you need to hide your custom notice when this event gets triggered.

showNotice

ShowNoticeEvent

When the consent notice gets displayed. If you have disabled our default consent notices to replace them with your own, you need to show your custom notice when this event gets triggered.

noticeClickAgree

NoticeClickAgreeEvent

When user clicks on agree on the notice

noticeClickMoreInfo

NoticeClickMoreInfoEvent

When user clicks on learn more on the notice

preferencesClickAgreeToAll

PreferencesClickAgreeToAllEvent

When user clicks on agree to all on the preferences popup

preferencesClickDisagreeToAll

PreferencesClickDisagreeToAllEvent

When user clicks on disagree to all on the preferences popup

preferencesClickPurposeAgree

PreferencesClickPurposeAgreeEvent

When user agree to a purpose on the preferences popup. (purposeId provided as a parameter)

preferencesClickPurposeDisagree

PreferencesClickPurposeDisagreeEvent

When user disagree to a purpose on the preferences popup. (purposeId provided as a parameter)

preferencesClickViewVendors

PreferencesClickViewVendorsEvent

When user clicks on view vendors on the preferences popup

preferencesClickSaveChoices

PreferencesClickSaveChoicesEvent

When user saves his choice on the preferences popup

preferencesClickVendorAgree

PreferencesClickVendorAgreeEvent

When user agree to a vendor on the preferences popup. (vendorId provided as a parameter)

preferencesClickVendorDisagree

PreferencesClickVendorDisagreeEvent

When user disagree to a vendor on the preferences popup. (vendorId provided as a parameter)

preferencesClickVendorSaveChoices

PreferencesClickVendorSaveChoicesEvent

When user saves his choice on the vendors view on the preferences popup

getDisabledPurposes

Get the list of purposes that have been disabled by the user.

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 purposes disabled by the user.

Example

Java
Didomi.getInstance().getDisabledPurposes();

getDisabledPurposeIds

Get the list of purpose IDs that have been disabled by the user.

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<String>

A set of type String containing the IDs of purposes disabled by the user.

Example

Java
Didomi.getInstance().getDisabledPurposeIds();

getDisabledVendors

Get the list of vendors that have been disabled by the user.

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 vendors disabled by the user.

Example

Java
Didomi.getInstance().getDisabledVendors();

getDisabledVendorIds

Get the list of vendor IDs that have been disabled by the user.

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<String>

A set of type String containing the IDs of vendors disabled by the user.

Example

Java
Didomi.getInstance().getDisabledVendorIds();

getEnabledPurposes

Get the list of purposes that have been enabled by the user.

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 purposes enabled by the user.

Example

Java
Didomi.getInstance().getEnabledPurposes();

getEnabledPurposeIds

Get the list of purpose IDs that have been enabled by the user.

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<String>

A set of type String containing the IDs of purposes enabled by the user.

Example

Java
Didomi.getInstance().getEnabledPurposeIds();

getEnabledVendors

Get the list of vendors that have been enabled by the user.

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 vendors enabled by the user.

Example

Java
Didomi.getInstance().getEnabledVendors();

getEnabledVendorIds

Get the list of vendor IDs that have been enabled by the user.

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<String>

A set of type String containing the IDs of vendors enabled by the user.

Example

Java
Didomi.getInstance().getEnabledVendorIds();

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

Java
Didomi.getInstance().getJavaScriptForWebView();

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

Java
Didomi.getInstance().getPurpose("purpose-id");

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

Java
Didomi.getInstance().getRequiredPurposes();

getRequiredPurposeIds

Get the list of purpose IDs 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<String>

A set of type String containing the IDs of required purposes.

Example

Java
Didomi.getInstance().getRequiredPurposeIds();

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

Java
Didomi.getInstance().getRequiredVendors();

getRequiredVendorIds

Get the list of vendor IDs 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<String>

A set of type String containing the IDs of required vendors.

Example

Java
Didomi.getInstance().getRequiredVendorIds();

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.

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

Java
Didomi.getInstance().getText("key");

getTranslatedText

Method used to get a translated text based on the current language and 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 text that we want to get translated.

Returns

Translated text.

Example

Java
Didomi.getInstance().getTranslatedText("key");

getUserConsentStatusForPurpose

Get the user consent status for a given purpose. You must also check that the user has given consent to a vendor before being able to load a vendor.

Parameters

Name

Type

Description

purposeId

String

The ID of the purpose to check the user consent for.

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

A Boolean that indicates if the user has given consent or not to the specific purpose.

null is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat null as false (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.

If consent is not required because GDPR does not apply to that user, this function will return true.

Example

Java
Didomi.getInstance().getUserConsentStatusForPurpose("analytics");

getUserConsentStatusForVendor

Get the user consent status for a given vendor. You must also check that the user has given consent to some or all of the purposes required by a vendor before loading the vendor. The function getUserConsentStatusForVendorAndRequiredPurposes does all the required checks for you so it might be a better choice.

Parameters

Name

Type

Description

vendorId

String

The ID of the vendor to check the user consent for. If you are checking an IAB vendor, pass the number as a String. If you are checking a custom vendor, prefix your vendor ID with c:.

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

A Boolean that indicates if the user has given consent or not to the specific vendor.

null is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat null as false (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.

If consent is not required because GDPR does not apply to that user, this function will return true.

Example

Java
// IAB vendors
Didomi.getInstance().getUserConsentStatusForVendor("1");
// Didomi vendors
Didomi.getInstance().getUserConsentStatusForVendor("google");
// Custom vendors (prefix vendor ID with c:)
Didomi.getInstance().getUserConsentStatusForVendor("c:custom-vendor-id");

getUserConsentStatusForVendorAndRequiredPurposes

Get the user consent status for a given vendor. We use the list of purposes declared for the vendor to make sure that it has consent for all of them. The required purposes are automatically setup for IAB or Didomi vendors and you must specify the required purposes for your custom vendors when configuring the tag.

Parameters

Name

Type

Description

vendorId

String

The ID of the vendor to check the user consent for.

If you are checking an IAB vendor, pass the number as a String.

If you are checking a custom vendor, prefix your vendor ID with c:.

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

A Boolean that indicates if the user has given consent or not to the specific vendor and all the purposes that require consent for that vendor.

null is returned if the consent status is not known yet. From a GDPR perspective, you'll want to treat null as false (ie no consent given) but it is helpful to know that the user has not interacted with the consent UI yet so that you can subscribe to events and wait for consent information to be collected.

If consent is not required because GDPR does not apply to that user, this function will return true.

Example

Java
// IAB vendors
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("1");
// Didomi vendors
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("google");
// Custom vendors (prefix vendor ID with c:)
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("c:custom-vendor-id");

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

Java
Didomi.getInstance().getVendor("vendor-id");

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

Java
Didomi.getInstance().hideNotice();

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

Java
Didomi.getInstance().hidePreferences();

initialize

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

Parameters

Name

Type

Nullable

Description

application

Application

No

A reference to your Application.

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

Boolean

No

Prevent the SDK from loading a remote configuration from the Didomi Console. Defaults to true (not loading remote config).

Set this parameter to false to use a remote consent notice configuration loaded from the Didomi Console.

Set this parameter to true to disable loading configurations from the Didomi Console.

Returns

Nothing

Example

Java
Didomi.getInstance().initialize(
this,
"<Your API key>",
null,
null,
null,
null,
false
);

isConsentRequired

Determine if consent is required for the user. This takes into account the location of the user and the configuration of the SDK:

  • If your app is configured to apply GDPR to all users then this function always returns true.

  • If your app is configured to apply GDPR to EU users only then this function returns true only if the user in the EU.

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

Java
Didomi.getInstance().isConsentRequired();

isUserConsentStatusPartial

Determine if all consent information is available for the user.

This function returns true if and only if:

  • Consent is required for the user (ie the user is in the EU or your tag is configured to apply GDPR to all users)

  • At least one vendor is configured (if there is no vendor configured, this function always returns false as there is no consent to collect)

  • We miss consent information for some vendors or purposes

If there is at least one piece of consent information missing for a single vendor/purpose, this function will return true. The consent notice is usually displayed when this function returns true although there is no guarantee of the direct mapping between the two.

An important edge case is when you add new vendors or if configured vendors ask for new purposes: the consent notice will be displayed again and this function will return true until the user has given or denied consent. Vendors that already had consent before will still operate normally as we only recollect consent for additional vendors/purposes.

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

Java
Didomi.getInstance().isUserConsentStatusPartial();

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

Java
Didomi.getInstance().isNoticeVisible();

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

Java
Didomi.getInstance().isPreferencesVisible();

isReady

Check if the SDK is ready.

Parameters

No parameter.

Returns

boolean

Example

Java
Didomi.getInstance().isReady();

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

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

setupUI

Internally, the setupUI method calls the showNotice method, which calls the shouldConsentBeCollected method. Therefore, by calling the setupUI method, the notice or preferences view will be displayed only if required.

Setup the SDK UI workflows. Method used to pass an Activity to the SDK that will use it as needed. By calling this method the notice or the preferences views will be displayed only once the SDK is ready and if consent should be collected.

Parameters

Name

Type

Description

activity

AppCompatActivity

An activity

Returns

Nothing

Example

Java
Didomi.getInstance().setupUI(this);

showNotice

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 displayed if required.

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

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

Java
Didomi.getInstance().showNotice();

showPreferences

In most cases this method should be called if the preferences screen 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 preferences screen will be displayed if required.

Show the preferences manager. This can be used to allow the user to update her preferences after the banner has been closed. We suggest adding a link with this function call somewhere app.

Parameters

Type

AppCompatActivity

Activity used to get the Support Fragment Manager used 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

Java
// We pass "this" as a parameter if this method is called from an Activity.
Didomi.getInstance().showPreferences(this);

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.

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

Java
Didomi.getInstance().reset();

setUserAgreeToAll

Report that the user has given consent to all purposes and vendors setup for your app programmatically. This function will log the consent on our platform and close the 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 consent status has changed (ie the user had given different consent information before this function got called).

Example

Java
Didomi.getInstance().setUserAgreeToAll();

setUserConsentStatus

Set the user consent 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 your consent information at once and not one by one.

Parameters

Name

Type

Description

enabledPurposeIds

Set<String>

Set of purpose IDs that the user has given consent to

disabledPurposeIds

Set<String>

Set of purpose IDs that the user has not given consent to

enabledVendorIds

Set<String>

Set of vendor IDs that the user has given consent to.

Prefix custom vendor IDs with c:.

disabledVendorIds

Set<String>

Set of vendor IDs that the user has not given consent to

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 consent status has changed (ie the user had given different consent information before this function got called).

Example

Java
Didomi.getInstance().setUserConsentStatus(
new HashSet<String>(Arrays.asList("cookies")),
new HashSet<String>(),
new HashSet<String>(Arrays.asList("123", "c:custom-vendor-id")),
new HashSet<String>()
);

setUserDisagreeToAll

Report that the user has denied consent to all purposes and vendors setup for your app programmatically. This function will log the consent information on our platform and close the banner.

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 consent status has changed (ie the user had given different consent information before this function got called).

Example

Java
Didomi.getInstance().setUserDisagreeToAll();

shouldConsentBeCollected

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

  • Consent has never been collected for this visitor yet

  • New consents 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.

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

Java
Didomi.getInstance().shouldConsentBeCollected()