Setup
Follow these steps to setup the Didomi Android and Android TV SDK:

Add the SDK to your project

We offer our SDK as a pre-compiled package that you can add to your application. We support SDK versions >= 16 (minSdkVersion(16)) and its target/compile version is 29 (targetSdkVersion(29) - minimum required for Google Play).
The package is distributed through the mavenCentral repository. Currently, JCenter is also still necessary to retrieve one of the sdk dependencies. Make sure both are added to your repositories in your build.gradle file:
build.gradle
1
buildscript {
2
repositories {
3
mavenCentral()
4
jcenter()
5
}
6
}
Copied!
Android Studio may display a warning message about JCenter, but this repository will still allow download of existing artifacts indefinitely: https://developer.android.com/studio/build/jcenter-migration
Add our SDK to your dependencies:
build.gradle
1
dependencies {
2
implementation 'io.didomi.sdk:android:1.47.0'
3
}
Copied!
Our SDK uses some Java 8 features. In order to use it, the following compileOptions must be specified in your application build.gradle :
build.gradle
1
android {
2
compileSdkVersion (...)
3
4
defaultConfig {
5
(...)
6
}
7
8
buildTypes {
9
(...)
10
}
11
12
compileOptions {
13
sourceCompatibility JavaVersion.VERSION_1_8
14
targetCompatibility JavaVersion.VERSION_1_8
15
}
16
}
Copied!
If your project is composed of several modules, make sure the compileOptions are defined in each module build.gradle , otherwise, compilation errors may occur.
Our SDK requires permissions to use the Internet connection and check its status so the following permissions will be merged to your AndroidManifest file:
AndroidManifest.xml
1
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.app">
2
<uses-permission android:name="android.permission.INTERNET" />
3
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
4
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
5
</manifest>
Copied!
Geolocation permissions (ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION) are not required but will be used if your app has them to avoid making extra HTTP requests for determining the user country.
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 disable the splitting by language in App Bundle configuration.
build.gradle
1
android {
2
bundle {
3
language {
4
enableSplit = false
5
}
6
}
7
}
Copied!

Add a Proguard rule for Didomi

The Didomi SDK uses GSON to generate JSON-encoded API events sent back to the Didomi platform for analytics. We use @SerializedName to indicate the name of the JSON properties and ensure that they are correctly encoded into JSON.
In certain configurations, the host app configuration for Proguard will obfuscate some key SDK classes and break the API events sent to Didomi. This translates into incorrect analytics for the app on Android and is hard to catch as it usually only becomes apparent once in production (as debug/test builds usually do not run through Proguard).
Usage of R8 in latest Android Studio versions may also necessitate additional rules to prevent errors in the Google gson library, used internally by the SDK.
Some proguard versions may also fail due to a bug in handling enums.
To ensure that this does not happen, add the following rules to your Proguard file:
1
# Keep the Didomi events classes
2
-keep class io.didomi.sdk.apiEvents.** { *; }
3
-keep enum io.didomi.sdk.apiEvents.** { *; }
4
5
# Prevent errors while using gson
6
-keepattributes Signature
7
-keep class * implements com.google.gson.JsonSerializer
8
-keep class * implements com.google.gson.JsonDeserializer
9
-keepclassmembers,allowobfuscation class * {
10
@com.google.gson.annotations.SerializedName <fields>;
11
}
12
13
# Prevent a bug in some proguard versions
14
-keep,allowshrinking,allowobfuscation enum com.iabtcf.v2.RestrictionType
15
-keep,allowshrinking,allowobfuscation enum io.didomi.sdk.ConsentStatus
Copied!
If you want to check whether that issue applies to you, you can monitor the events sent by the Didomi SDK in your production build.
Correct events should look like:
Notice how the parameters and user.token properties have a lot of data.
Incorrect events will look like this:
Notice how the parameters and user.token properties are empty.

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:
Application.java
1
package com.my.app;
2
3
import android.app.Application;
4
import android.util.Log;
5
6
import io.didomi.sdk.Didomi;
7
8
public class SampleApplication extends Application {
9
@Override
10
public void onCreate() {
11
super.onCreate();
12
13
try {
14
Didomi.getInstance().initialize(
15
this,
16
new DidomiInitializeParameters(
17
"<API key>"
18
)
19
);
20
21
// Do not use the Didomi.getInstance() object here for anything else than registering your ready listener
22
// The SDK might not be ready yet
23
24
Didomi.getInstance().onReady(() -> {
25
// The SDK is ready, you can now interact with it
26
});
27
} catch(Exception e) {
28
Log.e("App", "Error while initializing the Didomi SDK", e);
29
}
30
}
31
}
32
Copied!
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:
Activity.java
1
package io.didomi.sample;
2
3
import android.os.Bundle;
4
import androidx.fragment.app.FragmentActivity
5
import io.didomi.sdk.Didomi;
6
7
public class SampleActivity extends FragmentActivity {
8
9
@Override
10
protected void onCreate(Bundle savedInstanceState) {
11
super.onCreate(savedInstanceState);
12
13
Didomi.getInstance().setupUI(this);
14
}
15
}
16
Copied!
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.
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 package
    Remote 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.
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.
Application.java
1
Didomi.getInstance().initialize(
2
this,
3
new DidomiInitializeParameters("<API key>")
4
);
Copied!
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

Using a local file automatically disables the TCF integration. If your app uses the TCF, you must use a configuration from the Didomi Console.
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:
assets/didomi_config.json
1
{
2
"app": {
3
"name": "My App Name",
4
"privacyPolicyURL": "http://www.website.com/privacy",
5
"vendors": {
6
"iab": {
7
"all": true
8
}
9
},
10
"gdprAppliesGlobally": true,
11
"gdprAppliesWhenUnknown": true
12
}
13
}
Copied!
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:
Application.java
1
Didomi.getInstance().initialize(
2
this,
3
new DidomiInitializeParameters(
4
"<API key>",
5
null,
6
null,
7
null,
8
true
9
)
10
);
Copied!
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:
Application.java
1
Didomi.getInstance().initialize(
2
this,
3
new DidomiInitializeParameters(
4
"<API key>",
5
null,
6
"https://www.website.com/didomi_config.json"
7
)
8
);
Copied!
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).
1
{
2
"app": {
3
"vendors": {
4
"iab": {
5
"requireUpdatedGVL": false
6
}
7
}
8
}
9
}
Copied!
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).
1
{
2
"app": {
3
"vendors": {
4
"iab": {
5
"updateGVLTimeout": 10
6
}
7
}
8
}
9
}
Copied!
Last modified 11d ago