01
Install from pinned source
kotlin
includeBuild("Vendor/pact/sdks/android") {
dependencySubstitution {
substitute(module("com.pact:pact-consent"))
.using(project(":pact-consent"))
}
}kotlin
dependencies {
implementation("com.pact:pact-consent:0.1.0")
}The library requires Android API 23 or newer and Java 17.
02
Create the native client
kotlin
import com.pact.consent.*
val consent = PactConsentClient(
context = applicationContext,
configuration = PactConfiguration(
baseUrl = "https://consent.example.com",
tenantId = "acme",
consentScopeId = "customer-account",
policyVersion = "policy-2026-08",
region = "EU",
binding = PactDeploymentBinding.android("com.example.app"),
purposes = listOf(
PactPurposeDefinition(PactPurpose.ESSENTIAL, "Essential", "Required", true),
PactPurposeDefinition(PactPurpose.ANALYTICS, "Measurement", "Understand product use"),
PactPurposeDefinition(PactPurpose.MARKETING, "Advertising", "Relevant advertising"),
),
),
)03
Use managed Compose
kotlin
PactPrivacyButton(client = consent) { dismiss ->
ModalBottomSheet(onDismissRequest = dismiss) {
PactConsentSheet(client = consent, onDismiss = dismiss)
}
}04
Use the headless API
kotlin
consent.deny(setOf(PactPurpose.MARKETING))
consent.save(mapOf(
PactPurpose.ANALYTICS to true,
PactPurpose.MARKETING to false,
))
if (consent.isAllowed(PactPurpose.ANALYTICS)) startMeasurement()05
Link only after customer authentication
kotlin
val credential = customerApi.pactLinkCredential()
consent.link(credential)
consent.refresh()Anonymous choices remain in SharedPreferences until linking. The linked session is encrypted with Android Keystore and pending evidence remains queued for retry.