For the complete documentation index, see llms.txt. This page is also available as Markdown.

Android — Référence

Cette page est maintenue en anglais — une seule source évite qu'une traduction dérive de la réalité du SDK à chaque release.

Every method and event exposed by the Android SDK. Setup and the recommended integration order live in Setup.

Android SDK — SirDataCMPApi

The primary interface for Android publishers. All methods delegate to the SirDataCMPManager singleton.

Call initialize once per process, from the main thread, before any other SDK call. The methods marked "needs an initialized SDK" below throw IllegalStateException when called before initialize — for showConsentBanner, the consent screen throws when it opens.

Initialization

Method
Signature
Description

initialize

fun initialize(context: Context, partnerId: Int, configId: String)

Initialize with partner credentials. Main thread only. Writes IABTCF_CmpSdkID, IABTCF_CmpSdkVersion and IABTCF_PolicyVersion immediately, then loads the publisher configuration asynchronously; the keys written once it has loaded, before any choice, are listed in Setup, step 5. Throws IllegalStateException if the SDK is already initialized: call shutdown() first.

initialize

fun initialize(context: Context, config: SirDataCMPConfig)

Same, with a full configuration object — see SirDataCMPConfig below.

isInitialized

fun isInitialized(): Boolean

Returns true as soon as initialize has been called, before the configuration has loaded.

getInitError

fun getInitError(): StateFlow<String?>

null while the configuration loads and after it loaded; the error message once a load has failed (unknown config ID, network down…). Cleared by the next initialize. The same failure is logged as Config load failed: … — see Logging.

shutdown

fun shutdown()

Clears in-memory state and cancels a configuration load in flight. Stored consent stays in SharedPreferences. Main thread only.

Method
Signature
Description

showConsentBanner

fun showConsentBanner(activity: ComponentActivity)

Launches ConsentActivity with Compose UI, in the workflow the display decision selected. Fires cmpuishown event. Needs an initialized SDK.

showConsentBanner

fun showConsentBanner(activity: ComponentActivity, workflow: Workflow)

Same, in an explicit workflow. Pass Workflow.MANUAL_DISPLAY when re-opening from a settings screen: the banner shows the close cross at the top and a "Reject all" button whatever the refusal type the publisher configured, restarts the cappingInDays window, and is reported as load:revisit.

shouldCollectConsent

fun shouldCollectConsent(): Boolean

Whether the banner should be presented, per the web checkConsent() cascade. Answers immediately, so before the config lands it is provisional.

getConsentDisplayDecision

fun getConsentDisplayDecision(): ConsentDisplayDecision

shouldDisplay + workflow + reason, same cascade, also immediate. See Display decision.

awaitConsentDisplayDecision

suspend fun awaitConsentDisplayDecision(): ConsentDisplayDecision

Waits for the config, then decides — the order the web CMP has by construction. Prefer this at startup.

awaitConsentDisplayDecision

suspend fun awaitConsentDisplayDecision(timeoutMillis: Long): ConsentDisplayDecision

Same, bounded; past the deadline the decision may be provisional.

recordAskLater

fun recordAskLater()

Records an explicit "ask me later": the banner is not shown again for one hour, a fixed duration (not cappingInDays). Records no consent. Does nothing before initialize.

All four need an initialized SDK.

Method
Signature
Returns
Description

acceptAll

suspend fun acceptAll(): ConsentResult

ConsentResult

Accept all purposes, vendors, and features. Persists to SharedPreferences.

rejectAll

suspend fun rejectAll(): ConsentResult

ConsentResult

Reject all purposes, vendors, and features. Persists to SharedPreferences.

saveConsent

suspend fun saveConsent(): ConsentResult

ConsentResult

Save current selections (partial consent).

submitConsent

suspend fun submitConsent(userAction: UserActionResponse): ConsentResult

ConsentResult

Records the current selections and reports them with the given answer.

Each recorded choice fires useractioncomplete to TCF and GPP listeners and forwards the Google consent signals to the consent adapters. The result and state types (ConsentResult, ConsentState, ConsentData, UserActionResponse) are shared with iOS and listed at the end of Reference — iOS.

The string getters read SharedPreferences and return "" before initialize.

Method
Signature
Returns
Description

getTcString

fun getTcString(): String

String

IAB TC String (base64-encoded, encoded on the device).

getGppString

fun getGppString(): String

String

Global Privacy Platform string.

getUspString

fun getUspString(): String

String

CCPA/USP string (e.g., "1YN-"). Empty when no decision has been recorded — "1---" is an explicit assertion that US Privacy does not apply, not a neutral default.

getAddtlConsent

fun getAddtlConsent(): String

String

Google Additional Consent string.

isGdprApplies

fun isGdprApplies(): Boolean

Boolean

GDPR applicability. Once the config is loaded, context.gdprApplies as served by the API, as is: the server already folds forceGdpr into it, so the SDK no longer adds it on top. Device geo only before that.

isCcpaApplies

fun isCcpaApplies(): Boolean

Boolean

US Privacy applicability. Once the publisher configuration has loaded, context.ccpaApplies as served by the API (from the visitor's country and US state); device geo only before that.

getConsentState

fun getConsentState(): StateFlow<ConsentState>

StateFlow

Observable consent state flow. Needs an initialized SDK.

getConsentData

fun getConsentData(): ConsentData

ConsentData

Full consent data object. Needs an initialized SDK.

getConsentUpdates

fun getConsentUpdates(): StateFlow<Long>

StateFlow<Long>

Counter bumped on every change to the selections — each toggle in the consent UI, before the user saves, as well as each recorded choice. It emits its current value when collected. Use it as a signal to re-read the stored values, not as a count of decisions. A US choice (the US screen, or setCcpaOptOut) does not bump it: re-read getUspString() and getGppString() when the consent UI closes. Needs an initialized SDK.

getLastTcStringError

fun getLastTcStringError(): String?

String?

Outcome of the last server archive of a recorded choice (/consent-string): null when it succeeded or none has run, otherwise a message starting with /consent-string. The archive runs in the background after the choice is stored, so the value is set after submitConsent returns. Despite its name, it does not report on the TC string, which is encoded on the device. Needs an initialized SDK.

getPurposeConsents

fun getPurposeConsents(): String

String

Purpose consents bit field from SharedPreferences.

getVendorConsents

fun getVendorConsents(): String

String

Vendor consents bit field from SharedPreferences.

hasPurposeConsent

fun hasPurposeConsent(purposeId: Int): Boolean

Boolean

Check if specific purpose (1-indexed) has consent.

hasVendorConsent

fun hasVendorConsent(vendorId: Int): Boolean

Boolean

Check if specific vendor (1-indexed) has consent.

All three need an initialized SDK. GoogleConsentState is com.sirdata.cmp.adapter.GoogleConsentState.

Method
Signature
Returns
Description

getGoogleConsentState

fun getGoogleConsentState(): GoogleConsentState

GoogleConsentState

The Google consent signals computed from the current selections: what the adapters would receive.

getLastForwardedConsentState

fun getLastForwardedConsentState(): GoogleConsentState?

GoogleConsentState?

What was actually forwarded to the adapters, or null when no choice has been recorded since initialize.

getRegisteredAdapters

fun getRegisteredAdapters(): List<String>

List<String>

The adapters whose SDK is in the app: "Firebase Analytics", "AppsFlyer", "Adjust", "Branch".

GoogleConsentState carries adStorageGranted, analyticsStorageGranted, adUserDataGranted, adPersonalizationGranted, personalizationStorageGranted, functionalityStorageGranted, securityStorageGranted, isSubjectToGDPR, hasConsentForDataUsage and adSignalsFromTcf — true when the configuration leaves the three ad signals to Google, in which case the Firebase adapter does not send them. See Sharing consent with vendor SDKs.

IAB API Access

Method
Signature
Returns
Description

tcfApi

fun tcfApi(): TcfApiImpl

TcfApiImpl

IAB TCF CMP API v2 in-app interface.

gppApi

fun gppApi(): GppApiImpl

GppApiImpl

GPP API implementation.

uspApi

fun uspApi(): UspApiImpl

UspApiImpl

USP/CCPA API implementation.

TCF commands

The callback receives the data, a listener ID (or null) and a success flag, on the main thread. Only version 2 is supported: any other version, and any unknown command, calls back with success = false (ping answers whatever the version).

Command
Parameter
Callback data

ping

—

cmpId (92), cmpVersion, cmpStatus (stub until the configuration has loaded, then loaded), cmpLoaded, tcfPolicyVersion, and gdprApplies once it is determined

getTCData, getInAppTCData

ignored

The TC data read from the stored keys. success = false until the configuration has loaded

addEventListener

—

See the in-app command API: the callbacks carry no eventStatus in 2.0.0

removeEventListener

Listener ID (Int, Long, Double or String)

The listener ID; success says whether a listener was removed

getVendorList

—

gvlSpecificationVersion, vendorListVersion, tcfPolicyVersion, lastUpdated, purposes, vendors. success = false until the configuration has loaded

GPP commands

Command
Parameter
Callback data

ping

—

gppVersion (1), gppString, gppSid, applicableSections, cmpStatus, cmpLoaded

hasSection

Section name: tcfeuv2 or uspv1

true when the section is in IABGPP_GppSID

getSection

Section name: tcfeuv2 or uspv1

The section's fields, or null when it is absent

getGppData

—

gppVersion, gppString, gppSid, applicableSections

addEventListener

—

First the listener ID, then for each event a map with eventName (useractioncomplete, cmpuiclosed), gppString, gppSid and applicableSections

removeEventListener

Listener ID

—

hasSection and getSection do not know the US National section (usnat, ID 7) in 2.0.0: read it from IABGPP_7_String.

USP command

getUspData is the only command: version, uspString, notice, optOut and lspa. It reports the stored string when US Privacy applies, and 1--- otherwise.

CCPA Opt-Out

Method
Signature
Description

setCcpaOptOut

fun setCcpaOptOut(optedOut: Boolean)

Records the user's "Do Not Sell" choice: writes IABUSPrivacy_String and re-encodes the GPP string (sections 6 and 7). Call it from a control the user operates, never on their behalf. Main thread only. Does nothing before initialize. The consent UI's US screen calls it when the user saves. Does not bump the getConsentUpdates() counter.

isCcpaOptedOut

fun isCcpaOptedOut(): Boolean

Returns true if user opted out of sale.

Data Management

Method
Signature
Description

clearConsent

fun clearConsent()

Clears ALL persisted consent from SharedPreferences. For testing, or an explicit user data deletion request. Does nothing before initialize or after shutdown().


SirDataCMPConfig — Android Configuration

  • language is accepted but read by nothing in 2.0.0. The UI language is the one pinned in the publisher configuration in the Sirdata Console, if any; otherwise the device language, when the SDK supports it; otherwise the configuration's default language; otherwise English.

  • theme is accepted but read by nothing in 2.0.0 — see CmpTheme Enum.

  • debugMode only changes the main-thread contract: a call to initialize, shutdown or setCcpaOptOut off the main thread throws instead of being logged. Enable it in debug builds only — see Logging.

  • certificatePins (com.sirdata.cmp.api.CertificatePins) maps a host name to its sha256/… public-key pins, applied to the SDK's own HTTPS requests. A wrong pin blocks the requests to that host — on the cacheApiRoot host, the configuration then fails to load.

  • gdprDefaultApplies is the answer isGdprApplies() gives before the publisher configuration has loaded, when the device reports no country. Once the configuration has loaded, the API decides.

Builder

With the Android Gradle Plugin 8, your app's BuildConfig class is generated only when buildFeatures { buildConfig = true } is set in its module.

The builder also has language(...), theme(...) (no effect in 2.0.0) and certificatePins(CertificatePins(mapOf(host to listOf("sha256/…")))).

CmpTheme Enum

Value
Description

Default

Accepted, no effect in 2.0.0

Dark

Accepted, no effect in 2.0.0

Light

Accepted, no effect in 2.0.0

The consent UI takes its colors from the theme configured in the Sirdata Console, in its light or dark version according to the device's dark mode setting. When the configuration defines no dark version, the light one is used in dark mode too.


Display decision

ConsentDisplayDecision (com.sirdata.cmp.workflow) is what getConsentDisplayDecision() and awaitConsentDisplayDecision() return:

Workflow

com.sirdata.cmp.model.Workflow.

Value
Description

MAIN

The standard banner. Also the workflow of every decision that does not display.

APPLY_CHOICES

Returned when the stored choice is missing only partners: the banner asks only about what is left to decide.

COOKIEWALL

Returned when the configuration enables the cookie wall and the stored choice does not grant purpose 1.

COOKIEWALL_MODIFY

Set by the consent UI itself when the user modifies their choices from the cookie wall. The decision never returns it.

MANUAL_DISPLAY

Re-opening from a settings screen, passed by the app. The decision never returns it. See showConsentBanner above.

DisplayReason

com.sirdata.cmp.workflow.DisplayReason.

Value

shouldDisplay

Meaning

GDPR_NOT_APPLIES

false

GDPR does not apply — as the server answered, or, before the configuration has loaded, as estimated from the device.

CONSENT_REQUIRED

true

Something is left to ask.

CAPPING_ACTIVE

false

A capping window is running on a stored choice that does not grant purpose 1.

CAPPING_ASK_LATER

false

Nothing is stored, and "ask me later" was recorded less than an hour ago.

CONSENT_OK

false

The stored choice needs nothing more, or a capping window is running on a choice that grants purpose 1.

CONFIG_NOT_LOADED

true or false

Provisional: the configuration had not loaded, so only GDPR applicability, estimated from the device, and the presence of a stored TC string were evaluated. When that estimate says GDPR does not apply, the reason is GDPR_NOT_APPLIES instead.


Mis à jour

Ce contenu vous a-t-il été utile ?