Android TCF V2

Get AppConsent SDK

To add the AppConsent SDK to your Android project, follow the steps below :

In your global gradle.properties file, add the following and replace ${username} by the provided username and ${encrypted_password} by the provided encrypted password. Please contact us, if you don't have your ${username} and ${encrypted_password} .

appconsent_artifactory_client_username=${username}
appconsent_artifactory_client_password=${encrypted_password}

In your project build.gradle file, under allprojects/repositories add the following :

maven {
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
credentials {
username = "${appconsent_artifactory_client_username}"
password = "${appconsent_artifactory_client_password}"
}
}

In your application build.gradle file, under android add the following :

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/AL2.0'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/*.kotlin_module'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

In your application build.gradle add the following

dependencies {
implementation 'com.sfbx.appconsent:appconsent-core:${currentCoreVersion}'
implementation 'com.sfbx.appconsent:appconsent-ui:${currentUIVersion}'
}

Where currentCoreVersion = 1.0.2 and currentUIVersion = 1.0.2

How to use AppConsent

1 - Get your AppKey from the backofffice : https://app.appconsent.io

2 - Create AppConsentUI.

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.sfbx.appconsent.ui.AppConsentUI
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appConsentUI = AppConsentUI(
context = this,
appKey = "YOUR_APP_KEY",
forceApplyGDPR = true
) {
it.presentNotice(false)
}
}
}

If forceApplyGDPR is true , it forces CMP to display even if your country isn't subject to GDPR.

Function onReady() is called when AppConsent finished initializing. It can avoid bugs when you want to present notice just after creating AppConsentUI object.

3 - Then use appConsentUI object.

appConsentUI.consentGiven()

Return true if consent is given, false otherwise.

Add Listener

appConsentUI.addNoticeListener(object : AppConsentNoticeListener {
override fun onConsentGiven() {
}
override fun onError(error: AppConsentError) {
}
})

Remove Listener

appConsentUI.removeNoticeListener(listener)

Every time consent is updated, a new event will be fired in AppConsentNoticeListener .

Add Geolocation Listener

appConsentUI.addGeolocationListener(object : AppConsentLocationListener {
override fun onResult(allowed: Boolean) {
}
override fun onError(error: AppConsentError) {
}
})

Remove Geolocation Listener

appConsentUI.removeGeolocationListener(listener)

Every time geolocation consent is updated, a new event will be fired in AppConsentLocationListener

Display CMP notice

appConsentUI.presentNotice(false) // display CMP notice only if needed
appConsentUI.presentNotice(true) // force to display CMP notice

Display Geolocation CMP

appConsentUI.presentGeolocationNotice(false) // display Geolocation CMP only if needed
appConsentUI.presentGeolocationNotice(true) // force to display Geolocation CMP
appConsentUI.geolocationConsentGiven()

Return true if geolocation consent is given, false otherwise

Consentable allowed

appConsentUI.consentableAllowed(1)

Return true if consentable with id = 1 is allowed, false otherwise - It's the IAB purposes from 1 to 10

Stack Allowed

appConsentUI.stackAllowed(1)

Return true if stack with id = 1 is allowed, false otherwise.

Vendor allowed

appConsentUI.vendorAllowed(1)

Return true if vendor with id = 1 is allowed, false otherwise.

Set consentable Status

appConsentUI.setConsentableConsents(
mapOf(1 to ConsentStatus.ALLOWED, 2 to ConsentStatus.DISALLOWED),
object : AppConsentSetConsentableConsentsCallback {
override fun onSuccess() {
}
override fun onError(t: Throwable) {
}
}
)

Set consentables status, save it and send it to server.

Check for update

appConsentUI.checkForUpdate(object : AppConsentUpdateCallback {
override fun onResult(updated: Boolean) {
}
override fun onError(t: Throwable?) {
}
})

Check if consent must be updated (new gvl version, new consentables...).

Clear consents

appConsentUI.clearConsent()

Clear consents on mobile, but not on server.

Set external data

val map = mapOf<String, Any>("externalId" to "abze23", "otherData" to "{\"name\": \"test\"}")
appConsentUI.setExternalData(map)

Set external data and send it to server.

Get external data

val map: Map<String, Any> = appConsentUI.getExternalData()

4 - Retrieve your consents

Your consents are saved in SharedPreferences of your application. To know more about keys used to save your consents, please refer to the IAB documentation.