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

addEventListener

Add an event listener to catch events triggered by the SDK. See the dedicated section for more details

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
Java
1
Didomi.getInstance().getDeviceType();
Copied!

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
1
Didomi.getInstance().getDisabledPurposes();
Copied!

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
1
Didomi.getInstance().getDisabledPurposeIds();
Copied!

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
1
Didomi.getInstance().getDisabledVendors();
Copied!

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
1
Didomi.getInstance().getDisabledVendorIds();
Copied!

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
1
Didomi.getInstance().getEnabledPurposes();
Copied!

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
1
Didomi.getInstance().getEnabledPurposeIds();
Copied!

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
1
Didomi.getInstance().getEnabledVendors();
Copied!

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
1
Didomi.getInstance().getEnabledVendorIds();
Copied!

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
1
Didomi.getInstance().getJavaScriptForWebView();
Copied!

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 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
Java
1
Didomi.getInstance().getQueryStringForWebView();
Copied!

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
1
Didomi.getInstance().getPurpose("purpose-id");
Copied!

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
1
Didomi.getInstance().getRequiredPurposes();
Copied!

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
1
Didomi.getInstance().getRequiredPurposeIds();
Copied!

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
1
Didomi.getInstance().getRequiredVendors();
Copied!

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
1
Didomi.getInstance().getRequiredVendorIds();
Copied!

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
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
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
1
Didomi.getInstance().getText("key");
Copied!

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:
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
Java
1
Didomi.getInstance().getTranslatedText("key");
Copied!

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
1
Didomi.getInstance().getUserConsentStatusForPurpose("analytics");
Copied!

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
1
// IAB vendors
2
Didomi.getInstance().getUserConsentStatusForVendor("1");
3
4
// Didomi vendors
5
Didomi.getInstance().getUserConsentStatusForVendor("google");
6
7
// Custom vendors (prefix vendor ID with c:)
8
Didomi.getInstance().getUserConsentStatusForVendor("c:custom-vendor-id");
Copied!

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
1
// IAB vendors
2
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("1");
3
4
// Didomi vendors
5
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("google");
6
7
// Custom vendors (prefix vendor ID with c:)
8
Didomi.getInstance().getUserConsentStatusForVendorAndRequiredPurposes("c:custom-vendor-id");
Copied!

getUserLegitimateInterestStatusForPurpose

Get the user legitimate interest status for a given purpose.
Parameters
Name
Type
Description
purposeId
String
The ID of the purpose to check the user legitimate interest 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 allowed legitimate interest data processing to the specific purpose.
null is returned if the legitimate interest status is not known yet. From a GDPR perspective, you'll want to treat null as false (ie no legitimate interest status given) but it is helpful to know that the user has not interacted with the legitimate interest UI yet so that you can subscribe to events and wait for legitimate interest information to be collected.
Example
Java
1
Didomi.getInstance().getUserLegitimateInterestStatusForPurpose("measure_ad_performance);
Copied!

getUserLegitimateInterestForVendor

Get the user legitimate interest status for a given vendor. You must also check that the user has allowed legitimate interest data processing for some or all of the purposes required by a vendor before loading the vendor. The function getUserLegitimateInterestStatusForVendorAndRequiredPurposes 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 legitimate interest status 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 allowed legitimate interest data processing for the specific vendor.
null is returned if the legitimate interest 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 legitimate interest UI yet so that you can subscribe to events and wait for legitimate interest information to be collected.
Example
Java
1
// IAB vendors
2
Didomi.getInstance().getUserLegitimateInterestStatusForVendor("1");
3
4
// Didomi vendors
5
Didomi.getInstance().getUserLegitimateInterestStatusForVendor("google");
6
7
// Custom vendors (prefix vendor ID with c:)
8
Didomi.getInstance().getUserLegitimateInterestStatusForVendor("c:custom-vendor-id");
Copied!

getUserLegitimateInterestStatusForVendorAndRequiredPurposes

Get the user legitimate interest status for a given vendor. We use the list of purposes declared for the vendor to make sure that it has allowed legitimate interest data processing 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 legitimate interest status 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 allowed legitimate interest data processing to the specific vendor and all the purposes that require legitimate interest for that vendor.
null is returned if the legitimate interest status is not known yet. From a GDPR perspective, you'll want to treat null as false (ie no legitimate interest given) but it is helpful to know that the user has not interacted with the legitimate interest UI yet so that you can subscribe to events and wait for legitimate interest information to be collected.
Example
Java
1
// IAB vendors
2
Didomi.getInstance().getUserLegitimateInterestStatusForVendorAndRequiredPurposes("1");
3
4
// Didomi vendors
5
Didomi.getInstance().getUserLegitimateInterestStatusForVendorAndRequiredPurposes("google");
6
7
// Custom vendors (prefix vendor ID with c:)
8
Didomi.getInstance().getUserLegitimateInterestStatusForVendorAndRequiredPurposes("c:custom-vendor-id");
Copied!

getUserStatus

Get all the user consent status.
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 UserStatus object describing all the available and computed user information.
Parameter
Type
Description
purposes.global.disabled
Set<String>
Computed sets/lists of disabled IDs of purposes that have been chosen by the user regarding the consent or legitimate interest Legal Basis.
purposes.global.enabled
Set<String>
Computed sets/lists of enabled IDs of purposes that have been chosen by the user regarding the consent or legitimate interest Legal Basis. Purposes considered as essential will be part of the enabled IDs.
purposes.consent.disabled
Set<String>
Disabled IDs of purposes that have been explicitly chosen by the user regarding the consent Legal Basis.
purposes.consent.enabled
Set<String>
Enabled IDs of purposes that have been explicitly chosen by the user regarding the consent Legal Basis.
purposes.legitimateInterest.disabled
Set<String>
Disabled IDs of purposes that have been explicitly chosen by the user regarding the legitimate interest Legal Basis.
purposes.legitimateInterest.enabled
Set<String>
Enabled IDs of purposes that have been explicitly chosen by the user regarding the legitimate interest Legal Basis.
purposes.essential
Set<String>
IDs of purposes that are considered essential.
vendors.global.disabled
Set<String>
Computed sets/lists of disabled IDs of vendors that have been chosen by the user regarding the consent or legitimate interest Legal Basis. This takes into account the consent and legitimate interest required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.global.enabled
Set<String>
Computed sets/lists of enabled IDs of vendors that have been chosen by the user regarding the consent or legitimate interest Legal Basis. This takes into account the consent and legitimate interest required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.globalConsent.disabled
Set<String>
Computed sets/lists of disabled IDs of vendors that have been chosen by the user regarding the consent Legal Basis. This takes into account the consent required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.globalConsent.enabled
Set<String>
Computed sets/lists of enabled IDs of vendors that have been chosen by the user regarding the consent Legal Basis. This takes into account the consent required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.globalLegitimateInterest.disabled
Set<String>
Computed sets/lists of disabled IDs of vendors that have been chosen by the user regarding the legitimate interest Legal Basis. This takes into account the legitimate interest required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.globalLegitimateInterest.enabled
Set<String>
Computed sets/lists of enabled IDs of vendors that have been chosen by the user regarding the legitimate interest Legal Basis. This takes into account the legitimate interest required purposes linked to vendors. When computing this property, essential purposes will be considered as enabled.
vendors.consent.disabled
Set<String>
Disabled IDs of vendors that have been explicitly chosen by the user regarding the consent Legal Basis.
vendors.consent.enabled
Set<String>
Enabled IDs of vendors that have been explicitly chosen by the user regarding the consent Legal Basis.
vendors.legitimateInterest.disabled
Set<String>
Disabled IDs of vendors that have been explicitly chosen by the user regarding the legitimate interest Legal Basis.
vendors.legitimateInterest.enabled
Set<String>
Enabled IDs of vendors that have been explicitly chosen by the user regarding the legitimate interest Legal Basis.
userId
String
Didomi user id.
created
String
User choices creation date.
updated
String
User choices update date.
consentString
String
TFC consent as string.
additionalConsent
String
Additional consent.
Example
Java
1
UserStatus userStatus = Didomi.getInstance().getUserStatus();
2
3
// Enabled consent ids for vendors
4
Set<String> enabledVendorsConsentIds = userStatus.getVendors().getConsent().getEnabled()
Copied!

getUserStatusForVendor

Get the user consent and legitimate interest status for a given vendor.
Parameters
Name
Type
Description
vendorId
String
The ID of the vendor to check the user status 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 allowed both consent and legitimate interest data processing to the specific vendor.
If one of consent or legitimate interest data processing status is unknown or not allowed, false will be returned. If both are allowed by the user, the function will return true.
Example
Java
1
// IAB vendors
2
Didomi.getInstance().getUserStatusForVendor("1");
3
4
// Didomi vendors
5
Didomi.getInstance().getUserStatusForVendor("google");
6
7
// Custom vendors (prefix vendor ID with c:)
8
Didomi.getInstance().getUserStatusForVendor("c:custom-vendor-id");
Copied!

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
1
Didomi.getInstance().