Android TV

Get AppConsent TV 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} .
1
appconsent_artifactory_client_username=${username}
2
appconsent_artifactory_client_password=${encrypted_password}
Copied!
In your project build.gradle file, under allprojects/repositories add the following :
1
maven {
2
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
3
credentials {
4
username = "${appconsent_artifactory_client_username}"
5
password = "${appconsent_artifactory_client_password}"
6
}
7
}
Copied!
In your application build.gradle file, under android add the following :
1
packagingOptions {
2
exclude 'META-INF/DEPENDENCIES'
3
exclude 'META-INF/LICENSE'
4
exclude 'META-INF/LICENSE.txt'
5
exclude 'META-INF/license.txt'
6
exclude 'META-INF/NOTICE'
7
exclude 'META-INF/NOTICE.txt'
8
exclude 'META-INF/notice.txt'
9
exclude 'META-INF/ASL2.0'
10
exclude 'META-INF/AL2.0'
11
exclude 'META-INF/LGPL2.1'
12
exclude 'META-INF/*.kotlin_module'
13
}
14
15
compileOptions {
16
sourceCompatibility JavaVersion.VERSION_1_8
17
targetCompatibility JavaVersion.VERSION_1_8
18
}
Copied!
In your application build.gradle add the following
1
dependencies {
2
implementation 'com.sfbx.appconsent:appconsent-tv:${currentTvVersion}'
3
}
Copied!
Where currentTvVersion = 1.1.4
AppConsent uses androidX Jetpack, so it's not compatible with android.supportapplications.

How to use AppConsent

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

2 - Create AppConsentTV.

1
import android.app.Activity
2
import android.os.Bundle
3
import com.sfbx.appconsent.tv.AppConsentTV
4
5
class MainActivity : Activity() {
6
7
override fun onCreate(savedInstanceState: Bundle?) {
8
super.onCreate(savedInstanceState)
9
setContentView(R.layout.activity_main)
10
11
val appConsentTV = AppConsentTV(
12
context = this,
13
appKey = "YOUR_APP_KEY",
14
forceApplyGDPR = true,
15
theme = AppConsentTVTheme.Builder(this)
16
.iconDrawable(ContextCompat.getDrawable(this, R.drawable.ic_android))
17
.build()
18
) {
19
it.presentNotice(false)
20
}
21
}
22
}
Copied!
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 AppConsentTV object.
For now, you can only override theme and icon with a custom AppConsentTVTheme.

3 - Then use appConsentTV object.

1
appConsentTV.consentGiven()
Copied!
Return true if consent is given, false otherwise.

Add Listener

1
appConsentTV.addNoticeListener(object : AppConsentNoticeListener {
2
override fun onConsentGiven() {
3
4
}
5
6
override fun onError(error: AppConsentError) {
7
8
}
9
})
Copied!

Remove Listener

1
appConsentTV.removeNoticeListener(listener)
Copied!
Every time consent is updated, a new event will be fired in AppConsentNoticeListener .

Display CMP notice

1
appConsentTV.presentNotice(false) // display CMP notice only if needed
2
3
appConsentTV.presentNotice(true) // force to display CMP notice
Copied!
presentNotice(force : Boolean) is a local method that only check cache. See checkForUpdate() to fetch a notice update

Consentable allowed

1
appConsentTV.consentableAllowed(1)
Copied!
Return true if consentable with id = 1 is allowed, false otherwise - It's the IAB purposes from 1 to 10

Stack Allowed

1
appConsentTV.stackAllowed(1)
Copied!
Return true if stack with id = 1 is allowed, false otherwise.

Vendor allowed

1
appConsentTV.vendorAllowed(1)
Copied!
Return true if vendor with id = 1 is allowed, false otherwise.

Set consentable Status

1
appConsentTV.setConsentableConsents(
2
mapOf(1 to ConsentStatus.ALLOWED, 2 to ConsentStatus.DISALLOWED),
3
object : AppConsentSetConsentableConsentsCallback {
4
override fun onSuccess() {
5
6
}
7
8
override fun onError(t: Throwable) {
9
10
}
11
}
12
)
Copied!
Set consentables status, save it and send it to server.

Check for update

1
appConsentTV.checkForUpdate(object : AppConsentUpdateCallback {
2
override fun onResult(updated: Boolean) {
3
4
}
5
6
override fun onError(t: Throwable?) {
7
8
}
9
})
Copied!
Check if consent must be updated (new gvl version, new consentables...).

Clear consents

1
appConsentTV.clearConsent()
Copied!
Clear consents on mobile, but not on server.

Set external data

1
val map = mapOf<String, Any>("externalId" to "abze23", "otherData" to "{\"name\": \"test\"}")
2
3
appConsentTV.setExternalData(map)
Copied!
Set external data and send it to server.

Get external data

1
val map: Map<String, Any> = appConsentTV.getExternalData()
Copied!

4 - Retrieve your consents

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