Android

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} .
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
compileOptions {
2
sourceCompatibility JavaVersion.VERSION_1_8
3
targetCompatibility JavaVersion.VERSION_1_8
4
}
Copied!
Classic template development kit (SDK)
Clear template development kit (SDK)
In your application build.gradle add the following
1
dependencies {
2
implementation 'com.sfbx.appconsent:appconsent-ui:${currentUIVersion}'
3
}
Copied!
Where currentUIVersion = 1.1.14
In your application build.gradle add the following
1
dependencies {
2
implementation 'com.sfbx.appconsent:appconsent-ui-v3:${currentUIV3Version}'
3
}
Copied!
Where currentUIV3Version = 2.0.3
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 AppConsentUI.

1
import android.os.Bundle
2
import androidx.appcompat.app.AppCompatActivity
3
import com.sfbx.appconsent.ui.AppConsentUI
4
5
class MainActivity : AppCompatActivity() {
6
7
override fun onCreate(savedInstanceState: Bundle?) {
8
super.onCreate(savedInstanceState)
9
setContentView(R.layout.activity_main)
10
11
val appConsentUI = AppConsentUI(
12
context = this,
13
appKey = "YOUR_APP_KEY",
14
forceApplyGDPR = true
15
) {
16
it.presentNotice(false)
17
}
18
}
19
}
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 AppConsentUI object.

3 - Then use appConsentUI object.

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

Check if user country is subject to GDPR

1
appConsentUI.isSubjectToGDPR()
Copied!
Return true if user country is subject to GDPR, false otherwise.

Check if user Limited Tracking is Enabled

1
appConsentUI.sLimitedTrackingEnabled()
Copied!
Return true if limited ad tracking is enabled, false otherwise

User ID

1
appConsentUI.getUserId()
Copied!
Return the advertising id used by Appconsent.
if isLimitedTrackingEnabled() == false, it will be Google ADID otherwise a random UUID

Add Listener

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

Remove Listener

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

Add Geolocation Listener

1
appConsentUI.addGeolocationListener(object : AppConsentLocationListener {
2
3
override fun onResult(allowed: Boolean) {
4
5
}
6
7
override fun onError(error: AppConsentError) {
8
9
}
10
})
Copied!

Remove Geolocation Listener

1
appConsentUI.removeGeolocationListener(listener)
Copied!
Every time geolocation consent is updated, a new event will be fired in AppConsentLocationListener

Display CMP notice

1
appConsentUI.presentNotice(false) // display CMP notice only if needed
2
3
appConsentUI.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
the force : boolean here when false and the consent wasn't set before will show the notice , when true will show the notice setting's either the consent has been already given or not

Display Geolocation CMP

1
appConsentUI.presentGeolocationNotice(false) // display Geolocation CMP only if needed
2
3
appConsentUI.presentGeolocationNotice(true) // force to display Geolocation CMP
Copied!
1
appConsentUI.geolocationConsentGiven()
Copied!
Return true if geolocation consent is given, false otherwise

Consentable allowed

1
appConsentUI.consentableAllowed(1,0)
Copied!
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 for ex : purpose = 0 .

Extra consentable allowed

1
appConsentUI.extraConsentableAllowed("O56KePok")
Copied!
Return true if extra consentable is allowed, false otherwise. The parameter is the extraId of your extra purpose available in the back office.

Stack Allowed

1
appConsentUI.stackAllowed(1)
Copied!
Return true if stack with id = 1 is allowed, false otherwise. The id to pass is the iabId of your stack.

Vendor allowed

1
appConsentUI.vendorAllowed(1)
Copied!
Return true if vendor with id = 1 is allowed, false otherwise. The id to pass is the iabId of your vendor.

Extra vendor allowed

1
appConsentUI.extraVendorAllowed("EHJNieed")
Copied!
Return true if extra vendor is allowed, false otherwise. The parameter is the extraId of your extra vendor available in the back office.

All consentables allowed

1
appConsentUI.allConsentablesAllowed()
Copied!
return true if all are consentables allowed false otherwise

All stacks allowed

1
appConsentUI.allStacksAllowed()
Copied!
return true if all stacks are allowed false otherwise

All vendors allowed

1
appConsentUI.allVendorsAllowed()
Copied!
return true if all vendors are allowed false otherwise

User Accept All

1
appConsentUI.userAcceptAll()
Copied!
return true if all consentables , stacks and vendors are allowed false otherwise

Set consentable Status

1
appConsentUI.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.

Set extra consentable Status

1
appConsentUI.setExtraConsentableConsents(
2
mapOf("EHJNieed" to ConsentStatus.ALLOWED, "O56KePok" 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 extra consentables status, save it and send it to server. Ids are the extraId of your extra purpose available in the back office.

Check for update

1
appConsentUI.checkForUpdate(object : AppConsentUpdateCallback {
2
override fun onResult(needUpdate: Boolean) {
3
if (needUpdate) {
4
appConsentUI.presentNotice(false)
5
}
6
}
7
8
override fun onError(t: Throwable?) {
9
10
}
11
})
Copied!
Check if consent must be updated (new gvl version, new consentables...).
In this exemple, introduction page of the CMP will be displayed after a notice modification in back office.

Clear consents

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

GET / SET externalIds

1
val ids = appConsentUI.externalIds.toMutableMap()
2
ids["contractId"] = "AZR35G"
3
appConsentUI.externalIds = ids
Copied!
GET / SET external ids in cache and send it to server when open notice.

Save external ids

1
appConsentUI.saveExternalIds(
2
success = { },
3
failed = { }
4
)
Copied!
Send external ids in cache to the server.
1
val floatingPurposes = mapOf("floatingId" to true)
2
appConsentUI.saveFloatingPurposes(
3
floatingPurposes,
4
success = { },
5
failed = { }
6
)
Copied!
Set floating purpose consent in cache as a map and send them to the server.
Only one floating purpose will be send at this time (1.1.0-beta04). We match the given ids with the one set in the back office
1
appConsentUI.extraFloatingAllowed("floatingId")
Copied!
Return true if floating purpose is allowed, false otherwise.

Force save consents

1
appConsentUI.save(
2
onResult = {
3
4
},
5
onError = {
6
7
}
8
)
Copied!
Force SDK to send consents to the server. It can be useful if you update externalIds and you want to update them on the server.

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.
We also provide an additional key for Google Additionnal Consent IABTCF_AddtlConsent returning a String.

5 - Xchange

Classic template development kit (SDK)
Clear template development kit (SDK)
In your application build.gradle add the following
1
dependencies {
2
implementation 'com.sfbx.appconsent:appconsent-ui-xchange:${currentUIVersion}'
3
}
Copied!
Where currentUIVersion = 1.1.14
In your application build.gradle add the following
1
dependencies {
2
implementation 'com.sfbx.appconsent:appconsent-ui-v3-xchange:${currentUIV3Version}'
3
}
Copied!
Where currentUIV3Version = 2.0.3

Set xchange user data

1
appConsentUI.setXchangeUserData(
2
XChangeUserData.Builder()
3
4
.build()
5
)
Copied!
Save user data in cache, and when user give his consent, data are sent to server.

Add request location listener

1
appConsentUI.addRequestLocationListener(object : AppConsentRequestLocationListener {
2
override fun requestLocation() {
3
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
4
ActivityCompat.requestPermissions(
5
this@MainActivity,
6
arrayOf(
7
Manifest.permission.ACCESS_COARSE_LOCATION,
8
Manifest.permission.ACCESS_FINE_LOCATION,
9
Manifest.permission.ACCESS_BACKGROUND_LOCATION
10
),
11
REQUEST_PERMISSION_CODE
12
)
13
} else {
14
ActivityCompat.requestPermissions(
15
this@MainActivity,
16
arrayOf(
17
Manifest.permission.ACCESS_COARSE_LOCATION,
18
Manifest.permission.ACCESS_FINE_LOCATION
19
),
20
REQUEST_PERMISSION_CODE
21
)
22
}
23
}
24
})
Copied!
If your app need to track geolocation, you must implement AppConsentRequestLocation as above and start partners geolocation SDK inside the callback (we check if location permissions and geolocation consents are given) and when creating appConsentUI for future launch .

Huq

Use Huq SDK.
1
appConsentUI.startHuq()
2
3
appConsentUI.stopHuq()
Copied!

Smart-Traffik

Use Smart-Traffik SDK.
1
appConsentUI.startSmartTraffik() // start Smart-Traffik SDK when user gives his consent
2
3
appConsentUI.stopSmartTraffik() // stop Smart-Traffik SDK
Copied!
Last modified 20d ago