Android TV
Get AppConsent TV SDKβ
To add the AppConsent SDK to your Android project, follow the steps below :
Declaration of the repositoryβ
Gradle <6.8β
In the build.gradle
file at the root of your project, add the following:
repositories {
...
maven {
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
}
}
Gradle >=6.8β
In your settings.gradle
file, at the root of your project, add the following :
dependencyResolutionManagement {
...
repositories {
...
maven {
url "https://artifactory.datalf.chat/artifactory/app-consent-v2-release"
}
}
}
Library integrationβ
In your application build.gradle
add the following:
dependencies {
implementation 'com.sfbx.appconsent:appconsent-tv:${currentTvVersion}'
}
Where currentTvVersion = 1.1.45
How to use AppConsentβ
1. Get your AppKey from AppConsent : https://app.appconsent.ioβ
2. Create AppConsentTVβ
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"
) {
it.presentNotice(false)
}
}
}
info
Function onReady()
is called when AppConsent finished initializing. It can avoid bugs when you want to present notice just after creating AppConsentTV object.
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.