Mobile SDK (Android)

  • Updated


The Osano Android SDK allows developers a simple way to integrate consent capture and consent preferences into their Android applications. In contrast to our web solution, the Android SDK captures only consent records and does not tattle or actively block libraries from loading. Consent record and preference changes are stored remotely through our API and on the device for 365 days. If a user deletes the application, their preferences are deleted as well.

Features Provided

  • UI for end-users
    • Screens:
      • Banner
      • Manage Storage Preferences
    • Translation
    • Detect language and apply the legally required regional consent options 
  • Consent capture

Note: Currently the Android SDK only supports fully native components and will not pass consent preferences to any embedded web views. 

Running the Sample Application

  1. Get the zip file contents provided by Osano’s Sales & Support team.
  2. Extract the zip file contents.
  3. Open Android Studio, and open the extracted folder for the android SDK sample app.
  4. Select a device in Android Studio, and run it.

Installing the Android SDK

Add the following to the build.gradle file in your Android application.

repositories {
maven { url "" }
dependencies {
implementation ""

Updating to a New Version

To change the version of the SDK, replace the version to the newer SDK version you wish to use. If we wanted to use the 2.2.0 version of the SDK, replace 2.0.10 with the new version. When the project is built, the new version is downloaded and installed.

How do I use it?


How to Instantiate a ConsentManager object with ConsentManagerBuilder:

  val consentManager = ConsentManagerBuilder(this)
.timeout(3) // default is 10s for timer dialog


  • customerId - This can be retrieved via your consent manager configuration in the web app or via Osano customer support.
    • private const val CUSTOMER_ID = "123456789abcdefghi"
  • configId - Available in your consent manager configuration in the Osano web application (Both the config ID and the customer ID are included in your osano.js src="”)
    • sample: "11111111-2222-3333-4444-555555555555"
  • consentingDomain  - Optional value associated domain that this consent should be associated with.
    • Max characters - 256
    • private const val CONSENTING_DOMAIN = "http://<your-domain>"
  • setCountryCode - Optional character country code. For a list of consent dialog regions based on country, please visit Consent Banner Regions.
    • Ensures the correct variant is displayed in accordance with the laws of the respective country.
    • If not provided the SDK will use the device locale

Consent Dialogue

With ConsentDialogue, you can display user consent dialogues with built-in methods. This object will show timer/consent categories/no-consent-category dialogues based on your given country code. Instantiate a ConsentDialogue object with ConsentDialogue.Builder:

    ConsentDialogue.Builder(this, consentManager)
.setCountryCode(countryCode) // nullable. Default is the device's country code.
.setOnConsentResultListener(object : OnConsentResultListener {
override fun onAccept(consentedTo: List<Category>) {
String.format(getString(R.string.accepted), consentedTo),

override fun onDeny() {
Toast.makeText(applicationContext, getString(R.string.denied), Toast.LENGTH_SHORT).show()

The SDK offers three options for displaying the Consent banner dialogue:

  • As a Fragment
    • -> consentDialogueBuilder.showAsFragment(supportFragmentManager)
  • As a Dialogue
    • -> consentDialogueBuilder.showAsDialogue(supportFragmentManager)
  • As a BottomSheet
    • -> consentDialogueBuilder.showAsBottomSheet(supportFragmentManager)

You can also show the ConsentDialogue in "full screen" mode instead of a dialogue using :

ConsentDialogue.Builder(this, consentManager)

Personalize the ConsentDialogue UI to your branding using color resources for each of the UI elements. Custom color codes can be added to the colors.xml file and used in the UI. The SDK provides the ability to adjust the colors for the following elements within the consent banner dialog.

   ConsentDialogue.Builder(this, consentManager)

Set the data storage policy link to your own valid policy URL. It’s currently set to for testing purposes.

  • .setDataStoragePolicyLink("")


Using StoragePreferenceDialogue you can display all consent categories dialog with the built-in UI. With this UI, the user can choose to enable or disable any categories they want. Instantiate a StoragePreferenceDialogue object with 

StoragePreferenceDialogue.Builder(this, consentManager)
.setOnConsentStoredListener(object : OnConsentStoredListener() {
override fun onSuccess(consentedCategories: List<Category>) {
String.format(getString(R.string.consent_stored), consentedCategories),
override fun onFailure(throwable: Throwable?) {

The Osano SDK offers three options for displaying the storage preference dialog:

  • As a Fragment
    • -> storagePreferenceDialogue.showAsFragment(supportFragmentManager) 
  • As a Dialogue
    • -> storagePreferenceDialogue.showAsDialogue(supportFragmentManager)
  • As a BottomSheet
    • -> storagePreferenceDialogue.showAsBottomSheet(supportFragmentManager)

You can also show the StoragePreferenceDialogue in "full screen" mode instead of a dialog using StoragePreferenceDialogue#showAsScreen():

  StoragePreferenceDialogue.Builder(this, consentManager)

Personalize the StoragePreferenceDialogue UI using color resources for each of the UI elements. The SDK provides the ability to adjust the colors for the following elements within the Storage Preferences Dialogue:

   StoragePreferenceDialogue.Builder(this, consentManager)
.showAsDialogue(supportFragmentManager) <br>

CCPA Opt-Out Mode

Customers who know they are in CCPA opt-out mode may choose to not show the modal and set the end-user consent as accepting cookies

  • In order to provide a link to Collection Preferences, bind the storage preferences dialog to a link.
  • In order to opt users into certain preferences, you should be able to call the consentManager.storeConsent.
  • The consent banner dialog can be disabled in the UI by simply commenting out the following:
    • binding.btnShowMessaging.setOnClickListener{ showConsentDialogue() }
    • private fun showConsentDialogue({...})


API Only

You may create your own UI and call our public APIs and integrate them into your view easily:

   // did user consent?
// get list of user-consented categories
val consentedToCategories = consentManager.userConsentedTo
// get disclosures based on your customer id and config id
consentManager.getDisclosures(object : OnDisclosureListener() {
override fun onSuccess(@Nullable disclosures: List<Disclosure>?) {

override fun onFailure(throwable: Throwable) {

// store consented content remotely and locally
consentManager.storeConsent(consentedToCategories, object : OnConsentStoredListener() {
override fun onSuccess(@NonNull consentedCategories: List<Category>) {

override fun onFailure(@Nullable throwable: Throwable?) {

Blocking Libraries

You should map your libraries to the consent categories. When a user denies consent, those libraries should stop sending data. In addition, the next time the app is closed and opens, those libraries should not initialize. 

Upon request, we can provide our recommendations on what category your libraries map to.