Class Didomi
-
- All Implemented Interfaces:
public final class Didomi
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringVIEW_PURPOSESpublic final static StringVIEW_VENDORSpublic final static StringVIEW_SENSITIVE_PERSONAL_INFORMATIONprivate final BooleanisReadyprivate final BooleanisErrorprivate final BooleanisInitializedprivate final BooleanhasAnyStatusprivate final BooleanisConsentRequiredprivate final BooleanisUserConsentStatusPartialprivate final BooleanisUserLegitimateInterestStatusPartialprivate final BooleanisUserStatusPartialprivate final UserStatususerStatusprivate final CurrentUserStatuscurrentUserStatusprivate final Set<Purpose>requiredPurposesprivate final Set<String>requiredPurposeIdsprivate final Set<Vendor>requiredVendorsprivate final Set<String>requiredVendorIdsprivate final DeviceTypedeviceTypeprivate final StringqueryStringForWebView
-
Method Summary
Modifier and Type Method Description final BooleanisReady()Is the SDK ready? final BooleanisError()Has an error occurred during SDK initialization. final BooleanisInitialized()Was the SDK initialized? final BooleangetHasAnyStatus()final BooleanisConsentRequired()final BooleanisUserConsentStatusPartial()final BooleanisUserLegitimateInterestStatusPartial()final BooleanisUserStatusPartial()final UserStatusgetUserStatus()final CurrentUserStatusgetCurrentUserStatus()final Set<Purpose>getRequiredPurposes()final Set<String>getRequiredPurposeIds()final Set<Vendor>getRequiredVendors()final Set<String>getRequiredVendorIds()final DeviceTypegetDeviceType()final StringgetQueryStringForWebView()final UnitsetLogLevel(Integer minLevel)Set the minimum level of messages to logMessages with a level below minLevelwill not be logged.final Unitinitialize(Application application, DidomiInitializeParameters parameters)Initialize the Didomi SDK and load its configuration. final PurposegetPurpose(String purposeId)Get a purpose from its ID final VendorgetVendor(String vendorId)Get a vendor from its ID final IntegergetTotalVendorCount()Get number of vendors final IntegergetIabVendorCount()Get number of IAB vendors final IntegergetNonIabVendorCount()Get number of non-IAB vendors final BooleanshouldUserStatusBeCollected()Determine if the User Status (consent) should be collected or not. final BooleanshouldConsentBeCollected()Check if the consent should be collected depending on if we have any consents or if we have some consents but the number of days before displaying the notice again has not expired yet final BooleansetUserAgreeToAll()Enable all purposes and vendors for the user. final BooleansetUserDisagreeToAll()Update user status to disagree : disable consent and legitimate interest purposes, disable consent vendors, but still enable legitimate interest vendors. final BooleansetUserStatus(Set<String> enabledConsentPurposeIds, Set<String> disabledConsentPurposeIds, Set<String> enabledLIPurposeIds, Set<String> disabledLIPurposeIds, Set<String> enabledConsentVendorIds, Set<String> disabledConsentVendorIds, Set<String> enabledLIVendorIds, Set<String> disabledLIVendorIds)Set the user status for each purpose and vendor final BooleansetUserStatus(Boolean purposesConsentStatus, Boolean purposesLIStatus, Boolean vendorsConsentStatus, Boolean vendorsLIStatus)Set the user status globally final BooleansetCurrentUserStatus(CurrentUserStatus currentUserStatus)Set the user consent status final CurrentUserStatusTransactionopenCurrentUserTransaction()final CurrentUserStatusTransactionopenCurrentUserStatusTransaction()Open a CurrentUserStatusTransaction to modify the user status final Unitreset()Remove all consents and user information from the SDK. final UnitonReady(DidomiCallable callback)Provide a function that needs to be called once the SDK is ready Automatically call the function if the SDK is already ready (that's why this is not a standard event) final UnitonError(DidomiCallable callback)Provide a function that needs to be called if the SDK encounters an error during initialization. final UnitaddEventListener(EventListener listener)Add an event listener final UnitaddEventListener(DidomiEventListener listener)Add an event listener final UnitremoveEventListener(DidomiEventListener listener)Remove a previously added event listener final UnitaddVendorStatusListener(String id, DidomiVendorStatusListener listener)Add a listener to be triggered when the user status for the selected vendor changes The callback will be registered after the SDK is ready final UnitremoveVendorStatusListener(String id)Remove one or multiple previously added vendor status listeners final UnitsetupUI(FragmentActivity activity)Show the consent notice if required (ie if consent information is missing)This does not show the consent notice if all consent information is already available as consent was previously collected. final UnitforceShowNotice(FragmentActivity activity)Force show the consent notice without checking if consent is required final UnitshowNotice(FragmentActivity activity)Show the consent notice (if required, not disabled in the config and not already displayed) final UnithideNotice()Hide the notice if it is currently displayed final BooleanisNoticeVisible()Check if the consent notice is currently displayed final UnitshowPreferences(FragmentActivity activity, String view)Method used to show the preferences view, by previously updating the fragment manager property based on an activity. final UnitshowPreferences(FragmentActivity activity)Method used to show the preferences view, by previously updating the fragment manager property based on an activity. final UnithidePreferences()Hide the Preferences dialog final BooleanisPreferencesVisible()Check if the Preferences view is currently displayed final UnitupdateSelectedLanguage(String languageCode)Update the selected language of the Didomi SDK and any property that depends on it. final Map<String, String>getText(String key)Method used to get a dictionary/map for a given key in the form of { en: "Value in English", fr: "Value in French" } from the didomi_config.json file containing translations in different languages. final StringgetTranslatedText(String key)Method used to get a translated string for a given key from the didomi_config.json file based on the currently selected language. final StringgetJavaScriptForWebView(String extra)Get JavaScript to embed into a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebViewInject the returned tag into a WebView with evaluateJavaScript.final StringgetJavaScriptForWebView()Get JavaScript to embed into a WebView to pass the consent status from the app to the Didomi Web SDK embedded into the WebViewInject the returned tag into a WebView with evaluateJavaScript.final UnitsetUserAgent(String name, String version)Set custom user agent name and version final UnitsetUser(String organizationUserId, FragmentActivity activity, Boolean isUnderage)Set user information final UnitsetUser(String organizationUserId, FragmentActivity activity)Set user information final UnitsetUser(String organizationUserId)Set user information final UnitsetUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers, FragmentActivity activity, Boolean isUnderage)Set user information with authentication final UnitsetUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers, FragmentActivity activity)Set user information with authentication final UnitsetUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers)Set user information with authentication final UnitsetUser(UserAuthParams userAuthParams)Set user information with authentication final UnitclearUser()Remove organization user information and reset user id final UnitsetLocalProperty(String key, Object value)Internal use only. final static DidomigetInstance()Get Didomi instance. -
-
Method Detail
-
isError
final Boolean isError()
Has an error occurred during SDK initialization.
- Returns:
true if initialization failed
-
isInitialized
final Boolean isInitialized()
Was the SDK initialized?
- Returns:
true is the
initializefunction has been called even if the initialization is not complete (that would beready).
-
getHasAnyStatus
final Boolean getHasAnyStatus()
-
isConsentRequired
final Boolean isConsentRequired()
-
isUserConsentStatusPartial
final Boolean isUserConsentStatusPartial()
-
isUserLegitimateInterestStatusPartial
final Boolean isUserLegitimateInterestStatusPartial()
-
isUserStatusPartial
final Boolean isUserStatusPartial()
-
getUserStatus
final UserStatus getUserStatus()
-
getCurrentUserStatus
final CurrentUserStatus getCurrentUserStatus()
-
getRequiredPurposes
final Set<Purpose> getRequiredPurposes()
-
getRequiredPurposeIds
final Set<String> getRequiredPurposeIds()
-
getRequiredVendors
final Set<Vendor> getRequiredVendors()
-
getRequiredVendorIds
final Set<String> getRequiredVendorIds()
-
getDeviceType
final DeviceType getDeviceType()
-
getQueryStringForWebView
final String getQueryStringForWebView()
-
setLogLevel
final Unit setLogLevel(Integer minLevel)
Set the minimum level of messages to log
Messages with a level below
minLevelwill not be logged. Levels are standard levels fromandroid.util.Log(https://developer.android.com/reference/android/util/Log#constants_1):android.util.Log.VERBOSE (2)
android.util.Log.DEBUG (3)
android.util.Log.INFO (4)
android.util.Log.WARN (5)
android.util.Log.ERROR (6)
We recommend setting
android.util.Log.WARNin production- Parameters:
minLevel- Minimum level of messages to log
-
initialize
final Unit initialize(Application application, DidomiInitializeParameters parameters)
Initialize the Didomi SDK and load its configuration. This method should be called from your Application onCreate method.
- Parameters:
application- The application instance; this is used to access resources within the application's file access and preferences.parameters- DidomiInitializeParameters object specifying parameters to initialize the SDK.
-
getPurpose
final Purpose getPurpose(String purposeId)
Get a purpose from its ID
- Returns:
the Purpose matching the id
-
getVendor
final Vendor getVendor(String vendorId)
Get a vendor from its ID
- Returns:
the Vendor matching the id
-
getTotalVendorCount
final Integer getTotalVendorCount()
Get number of vendors
- Returns:
the count of all vendors
-
getIabVendorCount
final Integer getIabVendorCount()
Get number of IAB vendors
- Returns:
the count of IAB vendors
-
getNonIabVendorCount
final Integer getNonIabVendorCount()
Get number of non-IAB vendors
- Returns:
the count of non-IAB vendors
-
shouldUserStatusBeCollected
final Boolean shouldUserStatusBeCollected()
Determine if the User Status (consent) should be collected or not. User Status should be collected if:
Regulation is different from NONE and
User status is partial and
The number of days before displaying the notice again has exceeded the limit specified on the Console or no User Status has been saved
- Returns:
true if User Status (consent) should be collected
-
shouldConsentBeCollected
@Deprecated(message = "Use shouldUserStatusBeCollected instead", replaceWith = @ReplaceWith(imports = {}, expression = "shouldUserStatusBeCollected()")) final Boolean shouldConsentBeCollected()
Check if the consent should be collected depending on if we have any consents or if we have some consents but the number of days before displaying the notice again has not expired yet
- Returns:
true if consent should be collected
- Since:
Deprecated since version 1.88.0
-
setUserAgreeToAll
final Boolean setUserAgreeToAll()
Enable all purposes and vendors for the user.
- Returns:
true if user consent status was updated, false otherwise.
-
setUserDisagreeToAll
final Boolean setUserDisagreeToAll()
Update user status to disagree : disable consent and legitimate interest purposes, disable consent vendors, but still enable legitimate interest vendors.
- Returns:
true if user status was updated, false otherwise.
-
setUserStatus
final Boolean setUserStatus(Set<String> enabledConsentPurposeIds, Set<String> disabledConsentPurposeIds, Set<String> enabledLIPurposeIds, Set<String> disabledLIPurposeIds, Set<String> enabledConsentVendorIds, Set<String> disabledConsentVendorIds, Set<String> enabledLIVendorIds, Set<String> disabledLIVendorIds)
Set the user status for each purpose and vendor
- Parameters:
enabledConsentPurposeIds- ids of the consent purposes to enabledisabledConsentPurposeIds- ids of the consent purposes to disableenabledLIPurposeIds- ids of the legitimate interest purposes to enabledisabledLIPurposeIds- ids of the legitimate interest purposes to disableenabledConsentVendorIds- ids of the consent vendors to enabledisabledConsentVendorIds- ids of the consent vendors to disableenabledLIVendorIds- ids of the legitimate interest vendors to enabledisabledLIVendorIds- ids of the legitimate interest vendors to disable
-
setUserStatus
final Boolean setUserStatus(Boolean purposesConsentStatus, Boolean purposesLIStatus, Boolean vendorsConsentStatus, Boolean vendorsLIStatus)
Set the user status globally
- Parameters:
purposesConsentStatus- true if purposes on a consent basis should be enabled, false if they should be disabledpurposesLIStatus- true if purposes on a legitimate interest basis should be enabled, false if they should be disabledvendorsConsentStatus- true if vendors on a consent basis should be enabled, false if they should be disabledvendorsLIStatus- true if vendors on a legitimate interest basis should be enabled, false if they should be disabled- Returns:
true if user consent status was updated, false otherwise.
-
setCurrentUserStatus
final Boolean setCurrentUserStatus(CurrentUserStatus currentUserStatus)
Set the user consent status
- Parameters:
currentUserStatus- as CurrentUserStatus- Returns:
true if the status has been updated, false otherwise
-
openCurrentUserTransaction
@Deprecated(message = "Use openCurrentUserStatusTransaction instead", replaceWith = @ReplaceWith(imports = {}, expression = "openCurrentUserStatusTransaction()")) final CurrentUserStatusTransaction openCurrentUserTransaction()
-
openCurrentUserStatusTransaction
final CurrentUserStatusTransaction openCurrentUserStatusTransaction()
Open a CurrentUserStatusTransaction to modify the user status
-
reset
final Unit reset()
Remove all consents and user information from the SDK. If SDK is not ready, the reset will be performed during initialization.
-
onReady
final Unit onReady(DidomiCallable callback)
Provide a function that needs to be called once the SDK is ready Automatically call the function if the SDK is already ready (that's why this is not a standard event)
- Parameters:
callback- that is called once the SDK is ready.
-
onError
final Unit onError(DidomiCallable callback)
Provide a function that needs to be called if the SDK encounters an error during initialization. In this case, the SDK will never be ready and onReady will not be called. Automatically call the function if the SDK initialization has already failed
- Parameters:
callback- that is called if the SDK encounters an error
-
addEventListener
final Unit addEventListener(EventListener listener)
Add an event listener
- Parameters:
listener- the EventListener to add
-
addEventListener
final Unit addEventListener(DidomiEventListener listener)
Add an event listener
- Parameters:
listener- the DidomiEventListener to add
-
removeEventListener
final Unit removeEventListener(DidomiEventListener listener)
Remove a previously added event listener
- Parameters:
listener- the DidomiEventListener to remove
-
addVendorStatusListener
final Unit addVendorStatusListener(String id, DidomiVendorStatusListener listener)
Add a listener to be triggered when the user status for the selected vendor changes The callback will be registered after the SDK is ready
- Parameters:
id- the id of the vendor as Stringlistener- the listener as DidomiVendorStatusListener to trigger when the user status for the selected vendor changes
-
removeVendorStatusListener
final Unit removeVendorStatusListener(String id)
Remove one or multiple previously added vendor status listeners
- Parameters:
id- the id of the vendor as String
-
setupUI
final Unit setupUI(FragmentActivity activity)
Show the consent notice if required (ie if consent information is missing)
This does not show the consent notice if all consent information is already available as consent was previously collected.
This method should be called in the onCreate function of your main activity or in activities where you want the consent notice to be shown to the user. This should be called at least once on every app launch and should cover every path by which the user launches the app (including deep linking) to ensure that consent is collected as often as possible.
-
forceShowNotice
final Unit forceShowNotice(FragmentActivity activity)
Force show the consent notice without checking if consent is required
- Parameters:
activity- base activity to use for notice
-
showNotice
final Unit showNotice(FragmentActivity activity)
Show the consent notice (if required, not disabled in the config and not already displayed)
- Parameters:
activity- base activity to use for notice
-
hideNotice
final Unit hideNotice()
Hide the notice if it is currently displayed
-
isNoticeVisible
final Boolean isNoticeVisible()
Check if the consent notice is currently displayed
- Returns:
true if ConsentNoticeBottomFragment or ConsentNoticePopupFragment exists
-
showPreferences
@JvmOverloads() final Unit showPreferences(FragmentActivity activity, String view)
Method used to show the preferences view, by previously updating the fragment manager property based on an activity. It also specifies which view (vendors or purposes) opens first.
- Parameters:
activity- activity used to get the support fragment manager.view- view to show to the user (purposes or vendors).
-
showPreferences
@JvmOverloads() final Unit showPreferences(FragmentActivity activity)
Method used to show the preferences view, by previously updating the fragment manager property based on an activity. It also specifies which view (vendors or purposes) opens first.
- Parameters:
activity- activity used to get the support fragment manager.
-
hidePreferences
final Unit hidePreferences()
Hide the Preferences dialog
-
isPreferencesVisible
final Boolean isPreferencesVisible()
Check if the Preferences view is currently displayed
-
updateSelectedLanguage
final Unit updateSelectedLanguage(String languageCode)
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. 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.
- Parameters:
languageCode- international short code (Coded2) for selected language.
-
getText
final Map<String, String> getText(String key)
Method used to get a dictionary/map for a given key in the form of { en: "Value in English", fr: "Value in French" } from the didomi_config.json file containing translations in different languages.
The keys and values considered come from different places in the didomi_config.json file such as { notice: ... }, { preferences: ... } and { texts: ... }, giving the latter the highest priority in case of duplicates.
- Parameters:
key- string used as a key to find a dictionary/map that contains translation texts.- Returns:
a dictionary/map that contains the translation texts in different languages for the given key.
-
getTranslatedText
final String getTranslatedText(String key)
Method used to get a translated string for a given key from the didomi_config.json file based on the currently selected language.
The keys and values considered come from different places in the didomi_config.json file such as { notice: ... }, { preferences: ... } and { texts: ... }, giving the latter the highest priority in case of duplicates.
- Parameters:
key- string used as a key to find a translated string.- Returns:
a translated string based on the provided key and the selected language.
-
getJavaScriptForWebView
@JvmOverloads() final String getJavaScriptForWebView(String extra)
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.See https://developers.didomi.io/cmp/mobile-sdk/share-consent-with-webviews for more information.
- Parameters:
extra- Extra JavaScript to inject in the returned tag (or null)
-
getJavaScriptForWebView
@JvmOverloads() final String 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.See https://developers.didomi.io/cmp/mobile-sdk/share-consent-with-webviews for more information.
-
setUserAgent
final Unit setUserAgent(String name, String version)
Set custom user agent name and version
-
setUser
@JvmOverloads() final Unit setUser(String organizationUserId, FragmentActivity activity, Boolean isUnderage)
Set user information
- Parameters:
organizationUserId- Organization user IDactivity- Current activity, so notice is displayed if it is needed after synchronizationisUnderage- Whether the user is underage
-
setUser
@JvmOverloads() final Unit setUser(String organizationUserId, FragmentActivity activity)
Set user information
- Parameters:
organizationUserId- Organization user IDactivity- Current activity, so notice is displayed if it is needed after synchronization
-
setUser
@JvmOverloads() final Unit setUser(String organizationUserId)
Set user information
- Parameters:
organizationUserId- Organization user ID
-
setUser
@JvmOverloads() final Unit setUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers, FragmentActivity activity, Boolean isUnderage)
Set user information with authentication
- Parameters:
userAuthParams- User authentication parameterssynchronizedUsers- Additional users to synchronize, should be null in most casesactivity- Current activity, so notice is displayed if it is needed after synchronizationisUnderage- Whether the user is underage
-
setUser
@JvmOverloads() final Unit setUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers, FragmentActivity activity)
Set user information with authentication
- Parameters:
userAuthParams- User authentication parameterssynchronizedUsers- Additional users to synchronize, should be null in most casesactivity- Current activity, so notice is displayed if it is needed after synchronization
-
setUser
@JvmOverloads() final Unit setUser(UserAuthParams userAuthParams, List<UserAuthParams> synchronizedUsers)
Set user information with authentication
- Parameters:
userAuthParams- User authentication parameterssynchronizedUsers- Additional users to synchronize, should be null in most cases
-
setUser
@JvmOverloads() final Unit setUser(UserAuthParams userAuthParams)
Set user information with authentication
- Parameters:
userAuthParams- User authentication parameters
-
setLocalProperty
final Unit setLocalProperty(String key, Object value)
Internal use only. Can activate specific features currently in development.
-
getInstance
final static Didomi getInstance()
Get Didomi instance.
- Returns:
current instance or newly created instance of Didomi
-
-
-
-