Setup
Follow these steps to setup the Didomi Android and Android TV SDK:
Requirements
We offer our SDK as a pre-compiled package that you can add to your application. We support SDK versions >= 19 (minSdkVersion(19)
) and its target/compile version is the minimum required for Google Play.
Add the SDK to your project
The package is distributed through the mavenCentral repository. Make sure it is added to your repositories in your project build.gradle
file:
Add our SDK to your dependencies:
Our SDK uses some Java 8 features. In order to use it, the following compileOptions
must be specified in your application build.gradle
:
If your project is composed of several modules, make sure the compileOptions
are defined in each module build.gradle
, otherwise, compilation errors may occur.
If you are using gradle plugin version 7.0.0 or above, Java 8 compilation is the default, hence compileOptions
do not need to be set.
Our SDK requires permissions to use the Internet connection and check its status so the following permissions will be merged to your AndroidManifest
file:
Multidex
If your project already uses several libraries, it is possible that by adding Didomi it reaches the limit of 64K references. In this case, it is necessary to enable multidex in your project: https://developer.android.com/studio/build/multidex#groovy
Example of error that can be caused by reaching the 64K limit:
Languages
Didomi SDK supports the following languages.
Restricting the supported languages can reduce your application size.
Note that the Hebrew (he
) language code is rewritten as iw
, Indonesian (id
) as in
, and Yiddish (yi
) as ji
(see https://developer.android.com/reference/java/util/Locale.html#legacy-language-codes for more information).
For example: to add Hebrew language to the filtered list of language, you need to use iw
.
App bundles
The Didomi SDK can be configured to restrict the languages it supports. If the user device language is not in the supported languages list, and app is distributed with Android App Bundles on the play store, it is possible that texts are removed from the downloaded app. In this case, all the texts will be displayed in english, except the custom texts.
To avoid this behavior, it is possible to either
disable the splitting by language in App Bundle configuration.
dynamically retrieve missing languages from Play Store through Install Manager, as described in Android developer doc: https://developer.android.com/guide/playcore/feature-delivery/on-demand?hl=fr#lang_resources
Disable splitting by language
Get missing language through Install Manager
Initialize the SDK
Once our SDK has been added to your project, you need to initialize it. The initialization process will run in a background thread and prepare the SDK for interactions with the user and your application. It is important to launch the SDK initialization as soon as possible.
In the onCreate
function of your main Application
class, call the Didomi.getInstance().initialize
function and pass a reference to your Application
instance and your API key:
It is a good idea to have a try/catch block around the Didomi initialization code and log any error that might happen.
Keep in mind that the SDK initialization is an asynchronous process so you must avoid interacting with the Didomi
object until it is actually ready to handle your requests. Use the onReady
function to register a listener for the ready event.
Setup the SDK UI
Note: the setupUI method should be called only from your main/entry Activities
which in most cases should be once per app launch.
You do not need to call onReady
, isReady
or shouldConsentBeCollected
before calling setupUI
because they are called internally. Therefore, by calling this method the consent notice and preference views will only be displayed if it is required and only once the SDK is ready.
In order for the SDK to be able to display UI elements and interact with the user, you must provide a reference to your main activity. Call the setupUI
function of the SDK in the onCreate
lifecycle event of your main activity:
We use the activity to get the fragment manager and register our own lifecycle events. We do not keep a reference to the activity outside of the call to the setupUI
function to avoid leaks.
For Jetpack compose, you will need to extend FragmentActivity
instead of ComponentActivity.
Deep links
If you are using deep links or have multiple main activities in your app make sure that the setupUI
function is called on every activity that the user can launch the app on.
This will ensure that consent is always collected as needed and there is no path where the user can launch the app without consent being collected. If setupUI
is missing at some entry points, you will see lower consent rates as users will be using the app without giving consent.
Configure the SDK
We support three options for configuration the UI and the behavior of the SDK:
Didomi Console: the SDK is configured remotely from the Didomi Console
Local file: the SDK is configured from a
didomi_config.json
file embedded in your app packageRemote file: the SDK is configured from a remote
didomi_config.json
file
On Android TV / Fire TV, only Didomi Console option is enabled. Local and remote files configuration will be ignored.
From the Console (Recommended)
You can configure the consent notice in your app by creating a notice in your Didomi Console. It will automatically be linked to your app through your API Key and, optionally, your app package name. You can access the Didomi console here.
It is possible to disable this option by setting the disableDidomiRemoteConfig
parameter to true
. Default is false
.
The SDK will automatically use the remote configuration hosted by Didomi and cache it locally. The cached version is refreshed every 60 minutes.
Local file (deprecated)
Using a local file automatically disables the TCF integration. If your app uses the TCF, you must use a configuration from the Didomi Console.
Using a local file will prevent you to support multiple regulations.
In this option, you create your own SDK configuration file and embed in your app package.
The SDK behavior is configured in a didomi_config.json
file that must be placed at the root of your assets/
folder. Create a file with the following content to get started:
You also need to disable loading the remote configuration to ensure that only the local file is loaded and that no HTTP request is sent. Update your initialize
call to set the disableDidomiRemoteConfig
parameter to true
:
Your SDK is now setup. Read the Getting started section to learn more about how to configure it to match your app UI and requirements.
Remote file
Using your own remote file automatically disable the TCF integration. If your app uses the TCF, you must use a configuration from the Didomi Console.
Enabling this option will prevent the configuration from being loaded from the Didomi Console.
You can provide a remote URL for the SDK to download the didomi_config.json
configuration file from. That allows you to update the SDK configuration without having to re-publish you mobile application.
When that configuration is enabled, the SDK will automatically use the remote configuration and cache it locally. The cached version is refreshed every 60 minutes. If there is no connection available to download the remote file and no locally cached version, the SDK will try to use the local assets/didomi_config.json
as a fallback.
To enable that option, change your call to initialize to provide the remote file URL:
Also see the reference documentation of the initialize function for more information.
Download Global Vendor List (GVL)
Since version 1.28.0 the GVL will be downloaded by default from our API before the SDK is initialized. If you want to stop this behavior, provide the app.vendors.iab.requireUpdatedGVL
flat set to false in the CUSTOM JSON section when editing your notice on the Console app (or in your local didomi_config.json
file if that's the case).
A timeout can also be provided to specify a maximum timeout for the Download of the GVL. This can be done by providing the app.vendors.iab.updateGVLTimeout
property (in seconds).
Last updated