Info
Content

[Android] 2. API Documentation

acceptAll

Parameters
Name Type Description
onConsentReceivedCallback OnConsentReceivedCallback? Callback for handling consent received event.
Return

No return value

Example
func acceptAll(onFinish: @escaping () -> Void) {
  cmpManager?.acceptAll(onFinish: onFinish)
}


check

Parameters
Name Type Description
onCheckIsConsentRequiredCallback OnCheckIsConsentRequired fun isConsentRequired(isConsentRequired: Boolean) callback to determine if a consent is required or not
isCached Boolean = false if true the result is cached for one day
Return

None.

Example
cmpManager.acceptAll {
  coroutineScope.launch {
    snackbarHostState.showSnackbar(
      message = "All consents accepted",
      duration = SnackbarDuration.Short
    )
    consentStatus.value = showConsentStatus(cmpManager)
  }
}


checkAndOpenConsentLayer

Checks if user's consent is required and, if so, opens the consent layer UI.

Parameters
Name Type Description
context Context Application Context
appInterface CmpLayerAppEventListenerInterface? = null  
Return

No return value

Example
context.getActivity()?.let { activity ->
                cmpManager.checkAndOpenConsentLayer(activity)
            }


calledThisDay

Checks if the consent layer was requested today.

Parameters
None.
Return

TRUE if the user's consent was already requested today.

FALSE otherwise.

fun consentRequestedTodayAction() {
    val calledToday = cmpManager?.calledThisDay()
    if (calledToday != null) {
        println("Consent requested today: $calledToday")
    } else {
        println("Failed to retrieve consent request status for today.")
    }
}

disablePurposeList

Disables a list of purposes and updates the given consent.

Parameters
Name Type Description
purposes List List of purposes ids to disable
updateVendor Boolean flag if true also disable corresponding vendors
onConsentReceivedCallback OnConsentReceivedCallback?  
Return

No return value

Example
fun onFinish() {
    println("Notification: New consent received")
}

val purposes = listOf("1", "2")

// Option with callback
cmpManager?.disablePurposeList(purposes, ::onFinish)

// Option without callback
cmpManager?.disablePurposeList(purposes)

disableVendorList

Disables a list of vendors and updates the given consent.

Parameters
Name Type Description
vendors List List of vendor ids to enable.
onConsentReceivedCallback OnConsentReceivedCallback?  Callback for handling consent received event. it will be called when consent is received and processed
Return

No return value.

Example
fun onFinish() {
    println("Notification: New consent received")
}

val vendors = listOf("1", "2")

// Option with callback
cmpManager?.disableVendorList(vendors, ::onFinish)

// Option without callback
cmpManager?.disableVendorList(vendors)


enableVendorList

Enables a list of purposes and updates the given consent.

Parameters
Name Type Description
vendors List List of purpose ids to enable.
onConsentReceivedCallback function (optional) Callback for handling consent received event. It will be called when consent is received and processed
Return

No return value.

Example
fun onFinish() {
    println("Notification: New consent received")
}

val vendors = listOf("1", "2")

// Option with callback
cmpManager?.enableVendorList(vendors, ::onFinish)

// Option without callback
cmpManager?.enableVendorList(vendors)


enablePurposeList

Enables a list of vendors and updates the given consent.

Parameters
Name Type Description
purposes List List of purpose ids to enable.
updateVendor Boolean flag if true also enable corresponding vendors
onConsentReceivedCallback Function (optional)  
Return

No return value.

Example
fun onFinish() {
    println("Notification: New consent received")
}

val purposes = listOf("1", "2")

// Option with callback
cmpManager?.enablePurposeList(purposes, ::onFinish)

// Option without callback
cmpManager?.enablePurposeList(purposes)


exportCmpString

Exports the current CMP string representing the user's consent preferences.  

Parameters
None.
Return

The CMP base64 encoded string.

Example

fun exportConsentStringAction() {
    val exportString = cmpManager?.exportCmpString()
    println(exportString ?: "No string to export.")
}

getAllPurposes

Returns all purposes' IDs.

Parameters
None.
Return

A comma-separated string containing all purpose IDs.

Example
fun getAllPurposesAction() {
    val allPurposes = cmpManager?.getAllPurposes()
    if (allPurposes != null) {
        println("All purposes: $allPurposes")
        // Additional actions for getAllPurposes function can be added here
    } else {
        println("Failed to retrieve all purposes.")
    }
}


getAllPurposeList

Returns a list of all purpose IDs for a given CMP.

Return

List<String>

Example
fun getAllPurposeListAction() {
  // Action for getAllPurposeList function
  val allPurposes = cmpManager?.getAllPurposesList()
  if (allPurposes != null) {
    println("All purposes list: ${allPurposes.joinToString(", ")}")
  } else {
    println("Failed to retrieve all purposes list.")
  }
}


getAllVendors

Returns all vendors' IDs for a given CMP.

Parameters
None.
Return

A comma-separated string containing all vendors IDs.

Example
fun getAllVendorsAction() {
  // Action for getAllVendors function
  val allVendors = cmpManager?.getAllVendors()
  if (allVendors != null) {
    println("Printing all Vendors: $allVendors")
  } else {
    println("Failed to retrieve all vendors.")
  }
}


getAllVendorsList

Returns a list of all vendors' IDs for a given CMP.

Parameters
None.
Return

A List<String> containing all vendor IDs.

Example

fun getAllVendorsListAction() {
    val allVendors = cmpManager?.getAllVendorsList()
    if (allVendors != null) {
        println("All vendors list: ${allVendors.joinToString(", ")}")
    } else {
        println("Failed to retrieve all vendors list.")
    }
}


getConsentstring

Returns a string with the last given consent.

Parameters
None.
Return

A string with the last consent acknowledged by the user.

Example
fun getAllVendorsListAction() {
    val allVendors = cmpManager?.getAllVendorsList()
    if (allVendors != null) {
        println("All vendors list: ${allVendors.joinToString(", ")}")
    } else {
        println("Failed to retrieve all vendors list.")
    }
}


getDisabledPurposes

Returns all disabled purposes' IDs for a given CMP.

Parameters
None.
Return

A comma-separated string containing all disabled purposes' IDs.

Example
fun getDisabledPurposesAction() {
    val disabledPurposes = cmpManager?.getDisabledPurposes()
    if (disabledPurposes != null) {
        println("Disabled purposes: $disabledPurposes")
    } else {
        println("Failed to retrieve disabled purposes.")
    }
}

getDisabledVendors

Returns all disabled vendors' IDs for a given CMP.

Parameters
None.
Return

A comma-separated string containing all disabled vendors' IDs.

Example
fun getDisabledVendorsAction() {
    val disabledVendors = cmpManager?.getDisabledVendors()
    if (disabledVendors != null) {
        println("Disabled vendors: $disabledVendors")
    } else {
        println("Failed to retrieve disabled vendors.")
    }
}

getEnabledPurposes

Returns all enabled vendors' IDs for a given CMP.

Parameters
None.
Return

A comma-separated string containing all enabled vendors' IDs.

Example
fun getEnabledPurposesAction() {
    val enabledPurposes = cmpManager?.getEnabledPurposes()
    if (enabledPurposes != null) {
        println("Disabled purposes: $enabledPurposes")
    } else {
        println("Failed to retrieve enabled purposes.")
    }
}

getEnabledPurposeList

Returns a list all enabled purposes' IDs for a given CMP.

Parameters
None.
Return

A List<String> containing all enabled purposes' IDs.

Example
fun getEnabledPurposesAction() {
    val enabledPurposes = cmpManager?.getEnabledPurposes()
    if (enabledPurposes != null) {
        println("Enabled purposes: ${enabledPurposes.joinToString(", ")}")
    } else {
        println("Failed to retrieve enabled purposes list.")
    }
}

getEnabledVendors

Returns all enabled vendors' IDs for a given CMP.

Parameters
None.
Return

A comma-separated string containing all enabled vendors' IDs.

Example
fun getEnabledVendorsAction() {
    val enabledVendors = cmpManager?.getEnabledVendors()
    if (enabledVendors != null) {
        println("Enabled vendors: $enabledVendors")
    } else {
        println("Failed to retrieve enabled vendors.")
    }
}

getEnabledVendorList

Returns a list with all enabled vendors' IDs for a given CMP.

Parameters
None.
Return

A List<String> containing all enabled vendors' IDs.

Example
fun getEnabledVendorsAction() {
    val enabledVendors = cmpManager?.getEnabledVendors()
    if (enabledVendors != null) {
        println("Enabled vendors: ${enabledVendors.joinToString(", ")}")
    } else {
        println("Failed to retrieve enabled vendors.")
    }
}

getGoogleACString

Retrieves the Google additional consent ID (`addtlConsent`) string that was set by the consent manager.

For further information, check the Google Additional Consent technical specification.  

Parameters
None.
Return

A List<String> containing all enabled vendors' IDs.

Example
fun getGoogleConsentStringAction() {
    val googleACString = cmpManager?.getGoogleACString()
    if (googleACString != null) {
        println("Google Additional Consent String: $googleACString")
    } else {
        println("Failed to retrieve Google Additional Consent String.")
    }
}

getUSPrivacyString

Retrieves the US Privacy String. This U.S. privacy string is a cookie that stores information about disclosures made and choices selected by the website visitor regarding their consumer rights.

Parameters
None.
Return

A String with the US Privacy data set by consentmanager.

Example
fun getUSPrivacyStringAction() {
    val usPrivacyString = cmpManager?.getUSPrivacyString()
    if (usPrivacyString != null) {
        println("US Privacy string contents: $usPrivacyString")
    } else {
        println("Failed to retrieve US Privacy string.")
    }
}

hasConsent

Checks if the user already provided his consent. The consent layer can have the option to just close the layer. In that case, the user did not provided a consent.

Parameters
None.
Return

A String with the US Privacy data set by consentmanager.

Example
fun getHasConsentAction() {
    val hasConsent = cmpManager?.hasConsent()
    if (hasConsent != null) {
        val consentStatus = if (hasConsent) "Yes" else "No"
        println("Consent provided by the user? $consentStatus")
    } else {
        println("Failed to retrieve user consent.")
    }
}

hasPurposeConsent

Checks if the purpose ID is enabled based on the user consent.

Parameters
Name Type Description
purposeId String purpose id
Return

TRUE if

  • the user has given consent to the specified purpose OR
  • for any reason related to poor or no internet connection on the device, the consent for the purpose could not be retrieved. Please refer to the withErrorListener to handle these conditions during app launch, especially for new users who have not yet given any consent

FALSE otherwise.

Example
fun getHasPurposeConsentAction() {
    val purposeId = "purposeID" // Replace with actual purpose ID
    val hasPurposeConsent = cmpManager?.hasPurposeConsent(purposeId)
    if (hasPurposeConsent != null) {
        val consentStatus = if (hasPurposeConsent) "Yes" else "No"
        println("Purpose has consent provided by the user? $consentStatus")
    } else {
        println("Failed to retrieve user purpose consent.")
    }
}

hasVendorConsent

Checks if the vendor ID is enabled based on the user consent.

Parameters
Name Type Description
vendorId String vendor id
Return
  • the user has given consent to the specified vendor OR
  • for any reason related to poor or no internet connection on the device, the consent for the vendor could not be retrieved. Please refer to the withErrorListener to handle these conditions during app launch, especially for new users who have not yet given any consent

FALSE otherwise.

Example
fun getHasVendorConsentAction() {
    val vendorId = "vendorID" // Replace with actual vendor ID
    val hasVendorConsent = cmpManager?.hasVendorConsent(vendorId)
    if (hasVendorConsent != null) {
        val consentStatus = if (hasVendorConsent) "Yes" else "No"
        println("Vendor has consent provided by the user? $consentStatus")
    } else {
        println("Failed to retrieve user vendor consent.")
    }
}

importCmpString

Imports a CMP string representing the user's consent preferences. The string must be base64 encoded

Parameters
Name Type Description
consentString  String Base64 encoded string representing the consent
completionHandler function (optional) Callback completion handler to the method.
Return

None.

Example
val cmpString = "YourBase64EncodedConsentStringHere"

  typealias CmpImportCompletionHandler = (Error?) -> Unit

// Define the completion handler function
val completionHandler: CmpImportCompletionHandler = { error ->
    if (error != null) {
        println("Failed to import CMP string: ${error.message}")
    } else {
        println("CMP string imported successfully")
    }
}

cmpManager?.importCmpString(cmpString, completion = completionHandler)


initialize

Initialize function will initialize the consent layer and checks automatically if the user needs a consent or not. This function will eventually open the consent layer and Will interact wit the Apple Tracking Transparency API to ask the user for Consent

Parameters
Name Type Description
context Context App Context
cmpConfig CmpConfig The CmpConfig object is passed with the info regarding the appId, Domain, appName and language (optional)
Return

The CMPManagerobject.

Example

private fun initializeCmpManager() {
    CmpConfig.apply {
    id = cmpId
    domain = CMP_DOMAIN
    appName = cmpAppName
    language = cmpLanguage
    domainWhitelist = cmpDomainWhitelist
    timeout = 2000
    isDebugMode = true
  }
  CmpLog.setLogLevel(Log.VERBOSE)

  cmpManager = CmpManager.createInstance(this, CmpConfig)
}

openConsentLayer

Forcefully opens the CMP consent layer webview.

Parameters
Name Type Description
context Context App context.
Return

No return value.

Example
ActionButtonsRow("Open", "Check", "Open?") { action ->
  when (action) {
  "Open" -> context.getActivity()?.let {
    	cmpManager.openConsentLayer(it.applicationContext)
    }
  	.
  	.
    .
}


needsAcceptance

Parameters
None.
Return

TRUE if the user needs to give a consent.

FALSE otherwise.

Example
fun showConsentStatus(cmpManager: CmpManager?): String {
    return buildString {
        append("Cmp ID: ${CmpConfig.id}\n")
        append("Need Acceptance: ${cmpManager?.needsAcceptance()}\n")  // <=========
        append("ConsentString: ${cmpManager?.getConsentString()}\n")
        append("Has Consent: ${cmpManager?.hasConsent()}\n")
    }
}

rejectAll

Parameters
Name Type Description
onFinish function Optional. Callback for handling consent received event. it will be called when consent is received and processed.
Return

No return value.

Example
// Define the onFinish function
fun onFinish() {
    println("Notification: New consent has been received with a Reject All response.")
}

cmpManager?.rejectAll(::onFinish)

setCallbacks

Configures the callbacks available.

Parameters
Name Type Description
openListener OnOpenCallback

The callback to be invoked when the consent layer is opened.

closeListener OnCloseCallback

The callback to be invoked when the consent layer is closed.

cmpNotOpenedCallback OnCMPNotOpenedCallback

The callback to be invoked when the consent layer could not be opened.

onErrorCallback OnErrorCallback

The callback to be invoked when an error.

onButtonClickedCallback
OnButtonClickedCallback

The callback to be invoked to get information about which button was pressed to close the consent layer.

Return

No return value

Example
val existingInstance = instance?.get()
    existingInstance.setCallbacks(
      openListener = openListener,
      closeListener = closeListener,
      cmpNotOpenedCallback = cmpNotOpenedCallback,
      onErrorCallback = errorCallback,
      onButtonClickedCallback = cmpButtonClickedCallback
    )

withGoogleAnalyticsCallback

Set callback for retrieving Google Consentmode values.

Parameters
Name Type Description
analyticsListener CmpGoogleAnalyticsInterface The interface implementation to receive updates about Google Analytics consent mode.
Return

The current instance of CmpManagerInterface for chaining.

Example
private fun initializeCmpManager() {
  cmpManager = CmpManager.createInstance(this, CmpConfig).apply {
    withOpenListener(this@ConsentActivity)
    withCloseListener(this@ConsentActivity)
    withNotOpenedCallback(this@ConsentActivity)
    withErrorCallback(this@ConsentActivity)
    withButtonClickedCallback(this@ConsentActivity)
    withOnClickLinkCallback(this@ConsentActivity)
    withGoogleAnalyticsCallback(this@ConsentActivity) // <=============
    initialize(this@ConsentActivity)
  }
}


 

 

Back to top