Info
Content

[Android] 2. API Documentation

The CMPManager class provides methods to manage user consent for data processing and tracking. This documentation covers the main methods available for mobile app integration.

Initialization

Object UrlConfig(:UrlConfig)

Sets the URL configuration for the Consent Manager. Needs to be initialized with the value below, and passed to the getInstance method. 

Parameters:

  • id: String - The CMP ID
  • domain: String - The domain for consent management
  • language: String - The language code (e.g., "EN")
  • appName: String - The name of your app

Example:

val urlConfig = UrlConfig(
    id = "YOUR_CODE_ID_HERE",
    domain = "delivery.consentmanager.net",
    language = "EN",
    appName = "CMDemoAppKotlin"
)

setActivity(activity: Activity)

Sets the Activitythat will present the consent layer. It should be a ComponentActivity

Parameters:

  • viewController: ComponentActivity - The Activity where the consent layer will be presented.

Returns: None

Example:

CMPManager.shared.setPresentingViewController(self)

checkIfConsentIsRequired(completion: (Boolean) -> Unit)

Parameters:

  • completion: (Boolean) -> Unit - A closure called with the result, either true or false.

Returns: None

Example:

cmpManager.checkIfConsentIsRequired { needsConsent ->
	toastMessage = "Needs Consent: $needsConsent"
}

checkWithServerAndOpenIfNecessary(completion: (Result<Unit>) -> Unit)

Checks with the server if consent is required and opens the consent layer if necessary. This will make a network call to our servers via the WebView created inside our SDK, consuming one pageview in the process. This network call will send a message to our backend via JavaScript, whih will detect whether the device has a valid consent or not, which will in turn determine whether the consent layer needs to be displayed or not.  

Parameters:

  • completion: A closure called when the operation completes, with the result, either true or false.

Returns: None

Example:

cmpManager.checkWithServerAndOpenIfNecessary { result ->
    result.onSuccess {
	    toastMessage = "Check and Open Consent Layer operation done successfully."
    }.onFailure { error ->
    	toastMessage = "Check and Open Consent Layer operation failed with error: $error"
}

openConsentLayer(completion: (Result<Unit>) -> Unit)

Parameters:

  • completion: A closure called when the operation completes, returning either a sucess or an error. 

Returns: None

Example:

cmpManager.openConsentLayer { result ->
	result.onFailure { error ->
    	toastMessage = "Error: ${error.message}"
	}
}

exportCMPInfo()

Exports the current consent information stored on the device as a string. This method retrieves the consent string from the UserPreferences area of the device, which is base 64 encoded, decodes it and returns it as a plain string. 

Returns: String - The exported consent information

Example:

val cmpInfo = CMPManager.shared.exportCMPInfo()
Log.d("Exported CMP info: \(cmpInfo)")

hasPurposeConsent(id: String)

Parameters:

  • id: String - The ID of the purpose to check

Returns: Boolean - True if consent is given, false otherwise

Example:

val hasPurposeConsent = cmpManager.hasPurposeConsent(id: "c53")
Log.d("Has consent for purpose c53: \(hasPurposeConsent)")

hasUserChoice()

Checks if the user has made a choice regarding consents and this consent is stored on the device. It means that the user either accepted all consents, rejected all of them, or made a mixed choice of rejected and accepted consents, depending on the CMP design, which might allow the users to allow some of the consents and reject others. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: Boolean - true if the user has made a choice, false otherwise

Example:

val hasChoice = cmpManager.hasUserChoice()
print("User has made a choice: \(hasChoice)")

hasVendorConsent(id: String)

Parameters:

  • id: String - The ID of the vendor to check

Returns: Boolean - True if consent is given, false otherwise

Example:

val hasVendorConsent = cmpManager.hasVendorConsent(id: "s2789")
Log.d("Has consent for vendor s2789: \(hasVendorConsent)")

Purpose and Vendor Management

getAllPurposesIDs()

Retrieves all purpose IDs stored on the device, according to the CMP configurations. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of all purpose IDs

Example:

val allPurposes = cmpManager.getAllPurposesIDs()
Log.d("All purposes: \(allPurposes)")

getAllVendorsIDs()

Retrieves all vendor IDs stored on the device, according to the CMP configurations. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of all vendor IDs

Example:

val allVendors = cmpManager.getAllVendorsIDs()
Log.d("All vendors: \(allVendors)")

getDisabledPurposesIDs()

Retrieves the IDs of all disabled purposes stored on the device, according to the CMP configurations and the user choices. If the user accepts all the consents, this will be empty.  This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of disabled purpose IDs

Example:

val disabledPurposes = cmpManager.getDisabledPurposesIDs()
Log.d("Disabled purposes: \(disabledPurposes)")

getDisabledVendorsIDs()

Retrieves the IDs of all disabled vendors stored on the device, according to the CMP configurations. If the user accepts all the consents, this will be empty. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of disabled vendor IDs

Example:

val disabledVendors = CMPManager.shared.getDisabledVendorsIDs()
Log.d("Disabled vendors: \(disabledVendors)")

getEnabledPurposesIDs()

Retrieves the IDs of all enabled purposes stored on the device, according to the CMP configurations. If the user rejects all the consents, this will be empty. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of enabled purpose IDs

Example:

val enabledPurposes = cmpManager.getEnabledPurposesIDs()
Log.d("Enabled purposes: \(enabledPurposes)")

getEnabledVendorsIDs()

Retrieves the IDs of all enabled vendors stored on the device. If the user rejects all the consents, this will be empty. This information will only be up-to-date after the consent is properly persisted in the UserPreferences area, so if you're checking right after using methods that trigger changes in the consent like openConsentLayer, acceptAll or rejectAll, for example, then wait until the callback from those methods is triggered before accessing the method hasUserChoice, to make sure that the information is up-to-date.

Returns: List<String> - A list of enabled vendor IDs

Example:

val enabledVendors = cmpManager.getEnabledVendorsIDs()
Log.d("Enabled vendors: \(enabledVendors)")

acceptAll(completion: (Result<Unit>) -> Unit)

Parameters:

  • completion: A closure called when the operation completes, returning failure or success.

Returns: None

Example:

cmpManager.acceptAll { result ->
    result.onSuccess {
	    toastMessage = "All consents accepted"
  	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

acceptPurposes(purposes: List<String>, updatePurpose: Boolean, completion: (Result<Unit>) -> Unit)

Parameters:

  • purposes: List<String> - A list of purpose IDs to accept
  • updatePurpose: Boolean - Whether to update related purposes
  • completion: A closure called when the operation completes, returning either a failure or a success

Returns: None

Example:

cmpManager.acceptPurposes(listOf("c52", "c53"), true) { result ->
	  	result.onSuccess {
	  	toastMessage = "Purposes enabled"
  	}.onFailure { error ->
  		toastMessage = "Error: ${error.message}"
    }
}

acceptVendors(vendors: List<String>, completion: (Result<Unit>) -> Unit)

Parameters:

  • vendors: List<String> - A list of of vendor IDs to accept
  • completion: A closure called when the operation completes

Returns: None

Example:

cmpManager.acceptVendors(listOf("s2790", "s2791")) { result ->
	result.onSuccess {
		toastMessage = "Vendors Enabled"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

importCMPInfo(cmpString: String)

Parameters:

  • cmpString: String - The CMP string to import
  • completion: A closure called when the operation completes, returning either a failure or success

Returns: None

Example:

val cmpString = "Q1FERkg3QVFERkg3QUFmR01CSVRCQkVnQUFBQUFBQUFBQWlnQUFBQUFBQUEjXzUxXzUyXzUzXzU0XzU1XzU2XyNfczI3ODlfczI3OTBfczI3OTFfczI2OTdfczk3MV9VXyMxLS0tIw"
cmpManager.importCMPInfo(cmpString) { result ->
	result.onSuccess {
		toastMessage = "Vendors Enabled"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

rejectAll(completion: (Result<Unit>) -> Unit)

Parameters:

  • completion: A closure called when the operation completes

Returns: None

Example:

cmpManager.rejectAll { result ->
	result.onSuccess {
		toastMessage = "All consents rejected"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

rejectPurposes(purposes: List<String>, updateVendor: Boolean, completion: (Result<Unit>) -> Unit)

Parameters:

  • purposes: List<String> - A list of purpose IDs to reject
  • updateVendor: Boolean - Whether to update related vendors
  • completion: A closure called when the operation completes

Returns: None

Example:

cmpManager.rejectPurposes(listOf("c52", "c53"), true) { result ->
    result.onSuccess {
      toastMessage = "Purposes disabled"
    }.onFailure { error ->
      toastMessage = "Error: ${error.message}"
	}
}

rejectVendors(vendors: List<String>, completion: (Result<Unit>) -> Unit)

Parameters:

  • vendors: List<String> - A list of vendor IDs to reject
  • completion: A closure called when the operation completes, returning either a failure or a success

Returns: None

Example:

cmpManager.rejectVendors(listOf("s2790", "s2791")) { result ->
	result.onSuccess {
		toastMessage = "Vendors Disabled"
	}.onFailure { error ->
		toastMessage = "Error: ${error.message}"
	}
}

resetConsentManagementData()

Parameters:

None

Returns: None

Example:

cmpManager.resetConsentManagementData()

CMPManagerDelegate events

didReceiveConsent(consent: String, jsonObject: [String: Any])

This is triggered when the consent layer was closed after the user updating his/her consents OR when invoking methods that cause changes in the consents, like acceptAll, rejectAll, acceptVendors, rejectVendors, etc. It means that the user accepted of rejected some of all of the consents, and that those were correctly saved in the device.

didShowConsentLayer

This is triggered when the consent layer was actually displayed. It means that there was not a consent valid in the device, so a new one should be collected.

didCloseConsentLayer


This is triggered when the SDK checked the need for a consent, but it was not needed and the layer was not displayed. It means that there is already a valid in the device, so a new one is not necessary and tue consent layer will not be displayed.

didReceiveError

This is triggered when the SDK faced any error, returning its code.

 

Back to top