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 :
compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}
In your application build.gradle
add the following
dependencies {implementation 'com.sfbx.appconsent:appconsent-ui:${currentUIVersion}'}
Where currentUIVersion = 1.1.1
AppConsent uses androidX Jetpack, so it's not compatible with android.support
applications.
import android.os.Bundleimport androidx.appcompat.app.AppCompatActivityimport com.sfbx.appconsent.ui.AppConsentUIclass 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.
appConsentUI.consentGiven()
Return true
if consent is given, false
otherwise.
appConsentUI.isSubjectToGDPR()
Return true
if user country is subject to GDPR, false
otherwise.
appConsentUI.addNoticeListener(object : AppConsentNoticeListener {override fun onConsentGiven() {}override fun onError(error: AppConsentError) {}})
appConsentUI.removeNoticeListener(listener)
Every time consent is updated, a new event will be fired in AppConsentNoticeListener
.
appConsentUI.addGeolocationListener(object : AppConsentLocationListener {override fun onResult(allowed: Boolean) {}override fun onError(error: AppConsentError) {}})
appConsentUI.removeGeolocationListener(listener)
Every time geolocation consent is updated, a new event will be fired in AppConsentLocationListener
appConsentUI.presentNotice(false) // display CMP notice only if neededappConsentUI.presentNotice(true) // force to display CMP notice
presentNotice(force : Boolean)
is a local method that only check cache. See checkForUpdate()
to fetch a notice update
appConsentUI.presentGeolocationNotice(false) // display Geolocation CMP only if neededappConsentUI.presentGeolocationNotice(true) // force to display Geolocation CMP
appConsentUI.geolocationConsentGiven()
Return true
if geolocation consent is given, false
otherwise
appConsentUI.consentableAllowed(1)
Return true
if consentable with id = 1
is allowed, false
otherwise. The id
to pass is the iabId
of your purpose.
appConsentUI.extraConsentableAllowed("O56KePok")
Return true
if extra consentable is allowed, false
otherwise. The parameter is the extraId
of your extra purpose available in the back office.
appConsentUI.stackAllowed(1)
Return true
if stack with id = 1
is allowed, false
otherwise. The id
to pass is the iabId
of your stack.
appConsentUI.vendorAllowed(1)
Return true
if vendor with id = 1
is allowed, false
otherwise. The id
to pass is the iabId
of your vendor.
appConsentUI.extraVendorAllowed("EHJNieed")
Return true
if extra vendor is allowed, false
otherwise. The parameter is the extraId
of your extra vendor available in the back office.
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.
appConsentUI.setExtraConsentableConsents(mapOf("EHJNieed" to ConsentStatus.ALLOWED, "O56KePok" to ConsentStatus.DISALLOWED),object : AppConsentSetConsentableConsentsCallback {override fun onSuccess() {}override fun onError(t: Throwable) {}})
Set extra consentables status, save it and send it to server. Ids are the extraId of your extra purpose available in the back office.
appConsentUI.checkForUpdate(object : AppConsentUpdateCallback {override fun onResult(needUpdate: Boolean) {if (needUpdate) {appConsentUI.presentNotice(false)}}override fun onError(t: Throwable?) {}})
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.
appConsentUI.clearConsent()
Clear consents on mobile, but not on server.
val ids = appConsentUI.externalIds.toMutableMap()ids["contractId"] = "AZR35G"appConsentUI.externalIds = ids
GET / SET external ids in cache and send it to server when open notice.
appConsentUI.saveExternalIds(success = { },failed = { })
Send external ids in cache to the server.
val floatingPurposes = mapOf("floatingId" to true)appConsentUI.saveFloatingPurposes(floatingPurposes,success = { },failed = { })
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
appConsentUI.extraFloatingAllowed("floatingId")
Return true
if floating purpose is allowed, false
otherwise.
appConsentUI.save(onResult = {},onError = {})
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.
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.
In your project build.gradle
add the following
allprojects {repositories {...maven {url 'https://jitpack.io'credentials { username "jp_7arvpgitvans74fv9nudrkrvru" }}...}}
In your application build.gradle
add the following
dependencies {implementation 'com.sfbx.appconsent:appconsent-ui-xchange:${currentUIVersion}'}
Where currentUIVersion = 1.1.0-beta03
appConsentUI.setXchangeUserData(XChangeUserData.Builder().email("[email protected]").build())
Save user data in cache, and when user give his consent, data are sent to server.
appConsentUI.addRequestLocationListener(object : AppConsentRequestLocationListener {override fun requestLocation() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {ActivityCompat.requestPermissions(this@MainActivity,arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_BACKGROUND_LOCATION),REQUEST_PERMISSION_CODE)} else {ActivityCompat.requestPermissions(this@MainActivity,arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION),REQUEST_PERMISSION_CODE)}}})