Skip to main content
All CollectionsMobile consent solution
Cookie Information SDKs for Android
Cookie Information SDKs for Android

Learn how to set up Cookie Information SDKs (software development kits) for Android.

Updated over 3 months ago

This article will walk you through setting up Cookie Information SDKs (software development kits) for Android. This is an out-of-the-box solution to help make your Android app GDPR-compliant.

Before you start

Here are a few things to know before you start:

  • Cookie Information offers two SDKs, core and UI. To set up both, you need Kotlin support.

  • You need a Cookie Information account to set up the SDKs. For details, see the Cookie Information website.

  • The core SDK manages and tracks the user consent. It gives you the full flexibility around the UI. For more information, see GitHub.

  • The SDK includes a pre-built component that displays the consent banner to users, which is required before collecting their data. Cookie Information manages all the data.

    The UI SDK provides built-in screens for managing consents, offering an easy way to customize banners with your app’s colors and fonts to match its design. It also allows you to track which consents have been given and collect data accordingly.

This is what the component would look like:

SDK component for cookie banner

You can change the content of each consent type in Cookie Information Consent Management Platform (CMP), you’ll find more details later in the article. With the SDK, different texts and labels can be overridden with custom values.

  • Your users can consent to different purposes. In Cookie Information, these are called consent items. They can include different categories such as necessary, functional, statistical, and marketing. Each item is unique and can only be used once in the consent solution.

  • You must set up the same languages for each consent item. Otherwise, the consent banner won’t display correctly.

  • Make sure you have set up the necessary consent on the CMP.

Create a mobile consent solution

Before you install our library for Android, you need to create a mobile consent solution, here’s how to do it:

1. Login to Cookie Information.

2. Navigate to Mobile consent solutions. This will take you to the platform’s old UI.

Mobile consent solution menu in Cookie Information CMP.

3. Click +Create mobile consent solution.

create a mobile consent solution in Cookie Information CMP

4. In Solution details, name your mobile consent solution and choose the operating systems.

Mobile solution details in Cookie Information

5. (Optional) You can write a short description of what your mobile application is about.

6. Click CREATE.

7. You’ll be directed to the created Mobile Consent Solution Cookie Information. In Consent Items, find the consent item you want to set up the language for and click Edit.

edit consent item in Cookie Information CMP

8. Select the languages of the consent item from the drop-down list.

Add app description in Cookie Information

Note: The mobile consent solution you create comes by default with five content items: necessary, functional, statistical and marketing and privacy policy. You must set up the same language for each consent item. Otherwise, the consent banner won’t display correctly.

9. You can edit or remove the short and long texts that describe a given consent item.

edit the short and long description of the consent item in Cookie Information CMP

Install the UI SDK for Android

To install the UI SDK for Android, you need to create a mobile consent solution (see a dedicated section above). Ensure the necessary consents are set up in the platform.

Tech requirements:

  • Kotlin support

  • Min SDK 24

You’ll need the following identifiers: clientID, solutionId, and clientSecret, to initialize the SDK and activate the functionality. You can find the authentication keys for those in the Cookie Information Mobile consent solution > Installation and later copy the following: Solution ID, Client_ID and Client secret.

Cookie Information SDK for Android identifiers

Initialization

We recommend to set up either in the application's onCreate method or in the onCreate method of the launching activity.

This sample contains the minimum info needed to initialize the SDK.

ConsentsUISDK.init(
clientID: String //credential found on management platform,
clientSecret: String //credential found on management platform,
solutionId: String //credential found on management platform,
languageCode: String = "FR"//language code,
context: Context)

You can add custom stylings such as fonts, colors, etc. Find a sample here. To get all the language codes, see this article.

Parameters

Here are the parameters you are passing to the initialization function:

clientID (string, required)

The string is provided as part of the credentials.

clientSecret (string, required)

The string is provided as part of the credentials.

solutionId (string, required)

The string is provided as part of the credentials.

languageCode (string, required)

The language you want the consent banner to be displayed in.

Note: We don’t recommend using the device's language. The consent may not be available in the selected language. Ensure that any language you pass has all languages set up in the Consent Management Platform.

context

The context is needed to install the SDK.

Main SDK functions

Here’s how you can use the SDK.

Display the consent banner when the user has never given consent, or the solution version has changed

You can choose to show the consent banner only if the user hasn't previously accepted or rejected it.

suspend fun showPrivacyPopupIfNeeded(callingActivity: ComponentActivity, userId: String? = null): Flow<Result<List<UIConsentItem>>> 

Parameters

callingActivity

This is the activity that launches the banner displaying the consent.

userId

The ID of the user is being checked to see if consent has already been given on this device.

In this case, the banner will appear whenever it’s needed, either when the user hasn't given consent or when a version update requires renewed consent.

Always display the consent banner

This will display the consent banner whenever the function is called. This way, you’ll allow the user to update or change their mind about a given consent.

suspend fun showPrivacyPopup(callingActivity: ComponentActivity, userId: String?): Flow<Result<List<UIConsentItem>>> 

Parameters

callingActivity

The activity that launches the banner displaying the consent

userId

The unique ID of the user who needs to provide consent. This SDK supports multiple users per device locally.

Handling consent data after displaying the banner

On return from the banner, the flow will contain a list of UIConsentItem, this will include data about the consent, and if the user has accepted the consent or not. Only then may the app owner collect data, based on what has been granted.

It will return what consent decision the user made, and you can use that data later.

lifecycleScope.launch{
ConsentsUISDK.showPrivacyPopup(this@MainActivity, "userId").collect { result ->
result.fold(
onSuccess = { consentItems ->
//Here you have access to the users consent
},
onFailure = { throwable ->
//if anything failed, here is where it could be handled
}
)
}
}

Fetch the consent data the current user has accepted or rejected

This will retrieve the consent data the current user has accepted or rejected.

fun getSavedItemsAsFlow():MutableSharedFlow<Result<List<UIConsentItem>>> 

lifecycleScope.launch{
ConsentsUISDK.getSavedItemsAsFlow().collect {
it.fold(
onSuccess = { consentItems ->
//this is on return from the popup, we get //the list of items and set your //data collectors accordingly
}
},
onFailure = { throwable ->
Log.d(TAG, throwable.message ?: "no message")
}
)
}

Firebase as a data collector, and how it handles the data

Google consent mode (Google Analytics by Firebase)

Firebase will automatically collect data when integrated into your app unless you disable data collection by setting it to false.

When a user opens the app for the first time, they haven't given consent yet. Make sure to set data collection to false by default. You can do it by adding meta to the manifest file. See more details in the documentation here.

Once the user has given consent, you need to update Firebase’s data collection settings accordingly.

Firebase tracks four things that require consent:

  • analyticsStorage

  • adStorage

  • adUserData

  • adPersonalization

Here is a sample of how to implement this:

lifecycleScope.launch{
ConsentsUISDK.showPrivacyPopup(this@MainActivity).collect { result ->
result.fold(
onSuccess = { consentItems ->//this is on return from the popup, we get //the list of items
Firebase.analytics.setConsent {
analyticsStorage(//find analytics storage consent in list, and see if accepted)
adStorage(ConsentStatus.GRANTED)
adUserData(ConsentStatus.GRANTED)
adPersonalization(ConsentStatus.GRANTED)
}
},
onFailure = { throwable ->
Log.d(TAG, throwable.message ?: "no message")
}
)
}
}

You can get more details and sample implementations on GitHub.

Related articles

Did this answer your question?