Android SDK
Installation
MobileConsentsSDK is available through Gradle, by adding te dependency to your project.. Kotlin DSL
implementation("com.cookieinformation:mobileconsents:<latest_release>")
Groovy
implementation 'com.cookieinformation:mobileconsents:<latest_release>'
Initializing
Create an instance of the sdk, and initialize prior to accessing the sdk at any point. You can initialize with or without theming and styling (for theming and styling its required to have compose dependencies.) The SDK credentials can be fetched from the platform here: https://go.cookieinformation.com/login This SDK requires you to ensure the language used for the sdk, is fully set on the platform, and all data exists. So if you choose to use the sdk in German, please ensure all fields are set on the platform.
The recommended implementation would be having the sdk invoking (most likely) the showPrivacyPopUpIfNeeded, when needed, so just initialize prior to calling the method
The minimum required data for initializing the SDK would be the following:
ConsentsUISDK.init(
clientID = "<CLIENT_ID>",
clientSecret = "<CLIENT_SECRET>",
solutionId = "<SOLUTION ID>",
)
Here is an example of all the arguments and data that support the SKD.
ConsentsUISDK.init(
clientID = "<CLIENT_ID>",
clientSecret = "<CLIENT_SECRET>",
solutionId = "<SOLUTION ID>",
languageCode = "FR",//Can be null, in this case it will take the devices configured language.
typography = defaultTypography.copy(bodyMedium = TextStyle.Default),
customDarkColorScheme = darkColorScheme(
primary = Color.Yellow,
secondary = Color.Green,
tertiary = Color.Black
),
customLightColorScheme = lightColorScheme(
primary = Color.Red,
secondary = Color.Yellow,
tertiary = Pink40
),
)
UI language
The language set for the sdk, will be the language used for all components, and will ignore the systems language. In case no language has been set, (in the init function), the sdk will use the devices configured language. Its important to note, it is the developers responsibility to ensure that any potential languages to be used are set on CookieInformation's platform.
Using built-in mobile consents UI
SDK contains built-in screens for managing consents. Please ensure you set the correct language code you expect the consents to use, and that has been fully set on the platform.
Consents Screen
Standard flows
Presenting the privacy pop-up
To show the Privacy Pop Up screen, whatever the state is use showPrivacyPopUp
(typically used in settings to
allow for modification of the consent)
or to show the Privacy Pop Up screen in case the user has not consented to the latest version use showPrivacyPopUpIfNeeded
(typically used at startup to
present the privacy screen conditionally. See more below) method:
ConsentsUISDK.showPrivacyPopup(callingActivity).collect {
it.fold(
onSuccess = {
it.forEachIndexed { index, consentItem ->
Log.d("####", "onCreate: ${consentItem.title} ${consentItem.accepted}")
}
},
onFailure = { Log.d("####", it.message ?: "no message") }
)
}
The above function takes an optional completion block argument that should be used to react to the users consent and start or block various third-party SDKs.
Presenting the privacy pop-up conditionally
The showPrivacyPopUpIfNeeded
method is typically used to present the popup after app start (or at
a point the developer deems appropriate).
The method checks if a valid consent is already saved locally on the device and also checks if there
are any updates on the Cookie Information server. In case there is no consent saved or the consent
version is different from the one available on the server, the popup will be presented, otherwise
only the completion closure is called. Using the ignoreVersionChanges
parameter allows the
developer to turn off the version checking mechanism and ignore consent version changes coming from
the server.
ConsentsUISDK.showPrivacyPopupIfNeeded(callingActivity).collect {
it.fold(
onSuccess = {
it.forEachIndexed { index, consentItem ->
Log.d("####", "onCreate: ${consentItem.title} ${consentItem.accepted}")
}
},
onFailure = {
Log.d("####", it.message ?: "no message")
}
)
}
Tracking the changes of the accepted consents
ConsentsUISDK.getSavedItemsAsFlow().collect {
//collects emitted Result<List<ConsentItem>> objects, so can track the changes
}
Managing multiple users
This SDK supports multiple users, if you would like to identify you users, and ask each user to consents, just pass the userId into the methods, showPrivacyPopUp
etc.
The argument userId is by default null which represents an anonymous user.
Please note, user management is applicable per device, and not across multiple devices, so each user will need to interact on each device used.
Example for displaying for an anonymous user:
ConsentsUISDK.showPrivacyPopUpIfNeeded(callingActivity, null).collect { consents ->
//returns the result for an anonymous user
}
Example for displaying for a user identified as "user_email":
ConsentsUISDK.showPrivacyPopUpIfNeeded(callingActivity, "user_email").collect { consents ->
//returns the result for a user identified as user_email.
}
Handling errors
Both the showPrivacyPopUp
and showPrivacyPopUpIfNeeded
, return Flow<Result<List
ConsentsUISDK.showPrivacyPopUpIfNeeded(callingActivity, userId).collect { consents ->
if (consent.isSuccessful()) {
consents.forEach { consent ->
// handle user defined consent items such as age consent
print("Consent given for: ${consentItem.title} ${consentItem.accepted}")
}
} else { //failure.
//handle error
}
}
optional settings
Theming & Styling
The UI theme and font can be customized in the SDKs initializer, make sure you have Jetpack Compose dependencies in you project:
ConsentsUISDK.init(
clientID = "<CLIENT_ID>",
clientSecret = "<CLIENT_SECRET>",
solutionId = "<SOLUTION ID>",
languageCode = "FR",
typography = defaultTypography.copy(bodyMedium = TextStyle.Default),
customDarkColorScheme = darkColorScheme(
primary = Color.Yellow,
secondary = Color.Green,
tertiary = Color.Black
),
customLightColorScheme = lightColorScheme(
primary = Color.Red,
secondary = Color.Yellow,
tertiary = Pink40
),
)
Consent solution description and consent item texts can leverage HTML tags for basic text styling. Supported tags include:
<b>
for bolding text<i>
and<em>
for emphasizing text<br>
for line breaking<ul>
and<li>
for creating lists<a href>
for embedding links
Displaying the device identifier
All consents sent to the Cookie Information servers are identified by a unique device identifier that is generated randomly after opening the privacy popup for the first time. This ID is necessary for Cookie Information to retrieve consents saved by the end user.
During normal operation the identifier is not required, however in case the end user wants to access their saved consents, it is only possible if they provide the above mentioned identifier. When using the default user interface, the device identifier can be located at the bottom of the privacy policy page (after tapping "read more"). It can be copied to the clipboard by tapping the text.