How to integrate UniConsent CMP SDK for Android with mobile apps

UniConsent CMP is a package for handling GDPR IAB TCF 2.2 consent management in Android apps. You can find a demo app integrated with UniConsent CMP in the "uniconsent_demo" directory.

Prerequisites

  • UniConsent CMP plan with Mobile app support
  • UniConsent CMP SDK package (request from support)

Getting started

To include the UniConsent package in your Flutter project, add it as a dependency in your pubspec.yaml file:

dependencies:
  uniconsent:
    path: ../uniconsent

Then, sync the dependency by running the following command:

flutter pub get

Usage

To use the UniConsent CMP in your app, follow these steps:

Initialize the CMP with an App ID from your account manager:

// Init CMP with appId
UniConsent.instance.setAppId("YOUR_APP_ID_CHANGE_THIS");

Display the CMP UI:

// Display CMP UI
UniConsent.instance.launchCMP(context);

Automatically check if consent is expired when the vendorList updates:

// Automatic check if consent is expired when vendorList updates
UniConsent.instance.shouldRequestConsent().then((shouldUpdate) => {
  if (shouldUpdate)
    {
      // display CMP again
    }
});

Get the tcString if required:

// Get tcString if requried
UniConsent.instance.getConsentInfo().then((info) => print(info?.tcString));

Read the consent status:

// Read consent status
UniConsent.instance
    .getConsentInfo()
    .then((info) => if(info?.purposeConsents.contains(DataUsagePurpose.useLimitedDataToSelectAds)) {
        // do something
    });

Reset consent status if required:

// Reset consent status if required:
UniConsent.instance.clearAll();

Notes

  1. Users should have the ability to access a "Privacy Settings" button or link in the settings section of your application in order to open the CMP UI.
  2. You can utilize the shouldRequestConsent() function to check whether you should request new consent based on the status. Display the CMP UI as needed when a user opens the application.