Skip to main content

Introduction


The Osano Consent SDK for Android is a native framework that integrates with the Consent Management Platform on the Osano Website. To use this SDK effectively, you need an Osano account and a published Cookie Consent configuration.

Getting Started

ConsentManager Setup

The ConsentManager is the core object of the SDK. Here's how to create an instance:

import com.osano.mobile_sdk.ConsentManager

val consentManager = ConsentManager.Builder(this)
.setConfigId("YOUR_CONFIG_ID")
.setCustomerId("YOUR_CUSTOMER_ID")
.setConsentingDomain("YOUR_CONSENTING_DOMAIN")
.build()
note

The configId, customerId, and consentingDomain parameters are mandatory and must match your configuration on the Osano website. The consenting domain should be a fully qualified URL.

Optional Configuration

  • Additional User Information: .setExtUsrData("id")
  • Override country locale: .setCountryCode("us")
  • Override language: .setLanguageCode("es")
  • Set banner timeout: .setTimeoutInSeconds(3)

If not explicitly set the SDK will use country and language defaults as follows:

  • Country: Determined from the IP address of the device and provided via a CloudFront geolocation header during the consent configuration network request.
  • Langauge: Device language Locale.getDefault().language

UI Implementation

  1. ConsentDialog
  2. StoragePreferenceDialog

Both can be displayed in three presentation styles:

  • Dialog showAsDialog()
  • Fragment showAsFragment()
  • Bottom Sheet showAsBottomSheet()

ConsentDialog

val builder = ConsentDialog.Builder(this, consentManager)
.setOnConsentStoredListener(object : OnConsentStoredListener() {
override fun onSuccess(categories: Set<Category>) {
println(categories)
}
override fun onFailure(throwable: Throwable?) {
println("error")
}
})

// Present as dialog
builder.showAsDialog(supportFragmentManager)
note

By default, the ConsentDialog will show in a banner style best suited to the compliance requirements of the user's region.

Depending on the region, the dialog may have an implied consent with automatic timeout. This behavior is expected and can be configured on my.osano.com.

StoragePreferenceDialog

val builder = StoragePreferenceDialog.Builder(this, consentManager)
.setOnConsentStoredListener(object : OnConsentStoredListener() {
override fun onSuccess(categories: Set<Category>) {
println(categories)
}
override fun onFailure(throwable: Throwable?) {
println("error")
}
})

// Present as bottom sheet
builder.showAsBottomSheet(supportFragmentManager)

Customization

Customize the appearance using these optional methods:

builder
.setBackgroundColor(R.color.white)
.setTextColor(R.color.black)
.setAccentColor(R.color.blue)
.setPositiveColor(R.color.blue)
.setNegativeColor(R.color.gray)
.setPositiveTextColor(R.color.white)
.setNegativeTextColor(R.color.white)
.setDataStoragePolicyLink("https://www.example.com")

Using Custom UI

If you prefer to use your own UI, you can utilize the ConsentManager APIs directly:

// Store consent
val categories = setOf(Category.Essential, Category.Analytics)
consentManager.storeConsent(categories, object: OnConsentStoredListener {
override fun onSuccess(categories: Set<Category>) {}
override fun onFailure(t: Throwable) {}
})

// Check if user has consented
val hasConsented = consentManager.hasUserConsented()

// Get consented categories
val consentedCategories = consentManager.getConsentedCategories()

// Clear stored consent
consentManager.clearConsent()