Skip to content

Consent Handling

You can check the current consent status by calling:

val result = spConsentEngine.getConsentStatus("YOUR_APPLICATION_ID")
val status: SPConsentStatus = result.data
when (status) {
SPConsentStatus.PENDING -> {
// Show consent banner
}
SPConsentStatus.COLLECTED -> {
// Proceed normally
}
SPConsentStatus.RECOLLECTION_REQUIRED -> {
// Trigger re-consent flow
}
}
Enum constantMeaning
PENDINGConsent needs to be collected.
COLLECTEDConsent has already been obtained.
RECOLLECTION_REQUIREDConsent needs to be re-collected.

When the SDK determines that consent needs to be recollected (for example, a consent update/re-consent flow), you can fetch the reason by calling:

val result = spConsentEngine.getConsentRecollectionReason("YOUR_APPLICATION_ID")
val reason: SPConsentRecollectionReason? = result.data
reason?.let {
when (it) {
SPConsentRecollectionReason.EXPIRED -> { /* handle */ }
SPConsentRecollectionReason.STRUCTURE_CHANGED -> { /* handle */ }
}
}

If no recollection reason is available, reason will be null.

Enum constantMeaning
EXPIREDConsent has expired and needs to be re-collected.
STRUCTURE_CHANGEDPackages and services hash mismatch.

SDK enums are the authoritative representation for consent status and recollection reasons. The SDK guarantees the enum contract (what cases are possible), but does not guarantee that the underlying wire/raw string values are stable over time (those are serialization details and may change).

Strongly prefer enums e.g. SPConsentStatus or SPConsentRecollectionReason in app logic.

  • Use enums in the control flow: when (status) { ... } or when (reason) { ... }.
  • Avoid branching on raw keys such as "expired", "Collected", or "RecollectionRequired".
  • If you need your own string identifiers, define app-specific keys and create a custom mapping, for example:
val myReasonKey: String? = when (reason) {
SPConsentRecollectionReason.EXPIRED -> "MY_EXPIRED"
SPConsentRecollectionReason.STRUCTURE_CHANGED -> "MY_STRUCTURE_CHANGED"
null -> null
}

This guidance applies to all enum fields returned from SDK APIs.

To check whether a specific package is enabled based on user consent, you can call:

val result = spConsentEngine.getPackage(packageId, "YOUR_APPLICATION_ID")
val pkg = result?.data
if (pkg != null && pkg.isEnabled) {
// Enable features
}

This returns an SPDataMessage containing the SPMobilePackage. You should check isEnabled to determine whether the user has consented.

To launch the consent collection banner, use the following method:

spConsentEngine.showConsentBanner(activity)

This banner informs users about data collection and provides options to accept or deny consent. You can also display the secondary consent banner using:

spConsentEngine.showSecondaryBanner(activity)
Android app consent banner.

The consent banner supports customization options and displays a “Customize” button that allows users to adjust their consent preferences. When they click the customization button, they will be directed to the Preference Center, where they can:

  • View a list of frameworks and their services.
  • Enable or disable consent for specific services.

To display the Preference Center directly, simply start the Preference Center activity:

spConsentEngine.showPreferenceCenter(activity, "YOUR_APPLICATION_ID")

Declaring SPPreferenceCenter activity in the Manifest

Section titled “Declaring SPPreferenceCenter activity in the Manifest”

To properly use the Preference Center Activity, you need to declare it in your app’s AndroidManifest.xml file. Add the following line inside the <application> tag:

<activity
android:name="ai.secureprivacy.mobileconsent.ui.preference_center.SPPreferenceCenter"
android:theme="@style/Theme.SecurePrivacyMobile"
/>

This registers the SDK’s Preference Center activity, allowing it to be launched correctly.

You can mark certain services as essential. These services will not be optional for the user to deny, ensuring compliance with the app’s required functionalities.

The Preferences screen also includes tabs showcasing content related to the app’s privacy and cookie policies. This ensures users have access to essential information regarding their data handling.

Users can submit a request for their data by filling out a form in the Request Data section. This feature helps manage user data requests in compliance with privacy regulations.