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}
.
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-tv:${currentTvVersion}'
}
Where currentTvVersion = 1.1.15
caution
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
import android.app.Activity
import android.os.Bundle
import com.sfbx.appconsent.tv.AppConsentTV
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val appConsentTV = AppConsentTV(
context = this,
appKey = "YOUR_APP_KEY",
forceApplyGDPR = true,
theme = AppConsentTVTheme.Builder(this)
.iconDrawable(ContextCompat.getDrawable(this, R.drawable.ic_android))
.build()
) {
it.presentNotice(false)
}
}
}
info
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
- Check if user gave consent
appConsentTV.consentGiven()
Return true
if consent is given, false
otherwise.
- Consent listener
Add Listener
appConsentTV.addNoticeListener(object : AppConsentNoticeListener {
override fun onConsentGiven() {
// ...
}
override fun onError(error: AppConsentError) {
// ...
}
})
Remove Listener
appConsentTV.removeNoticeListener(listener)
Every time consent is updated, a new event will be fired in AppConsentNoticeListener
.
- Display CMP notice
appConsentTV.presentNotice(false) // display CMP notice only if needed
appConsentTV.presentNotice(true) // force to display CMP notice
info
presentNotice(force : Boolean)
is a local method that only check cache. See checkForUpdate()
to fetch a notice update
- Consentable allowed
appConsentTV.consentableAllowed(1,0)
Return true
if consentable with id = 1
and consentableType = 0
is allowed, false
otherwise. The id
to pass is the iabId
of your purpose and the consentableType
is the type, e.g: purpose = 0
.
- Stack Allowed
appConsentTV.stackAllowed(1)
Return true
if stack with id = 1
is allowed, false
otherwise.
- Vendor allowed
appConsentTV.vendorAllowed(1)
Return true
if vendor with id = 1
is allowed, false
otherwise.
- Set consentable status
appConsentTV.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
appConsentTV.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
appConsentTV.clearConsent()
Clear consents on mobile, but not on server.
- Set external data
val map = mapOf<String, Any>("externalId" to "abze23", "otherData" to "{\"name\": \"test\"}")
appConsentTV.setExternalData(map)
Set external data and send it to server.
- Get external data
val map: Map<String, Any> = appConsentTV.getExternalData()
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.