Two demo applications, on in Java and one in Kotlin, showcasing the integration and functionality of the consentmanager CMP (Consent Management Platform) SDK v2 for Android. This app demonstrates how to implement and interact with various consent management features.
For more information about the Consentmanager CMP SDK, visit consentmanager.net and our help documentation.
This demo app provides a comprehensive interface to test and validate the CMP SDK's functionality, including:
- Consent status checking
- Purpose and vendor management
- Consent string handling
- UI layer integration
-
CmpManager
: A singleton wrapper around the CMP SDK that handles:- SDK initialization and configuration
- Event handling (errors, UI open/close events)
- Callback management
-
CmpUIConfig
: Configuration class for customizing the consent UI presentation -
CmpWebView
: WebView component that handles the consent interface rendering -
CmpCallbackManager
: Manages all callback events from the SDK
-
Basic SDK Setup
- SDK initialization with custom configuration
- Event listener registration
- Error handling
-
Consent Management
- Check user consent status
- Get/Set consent string
- Import external consent strings
- Accept/Reject all consents
-
Purpose Management
- List all purposes
- Check specific purpose consent
- Enable/Disable individual purposes
- Get enabled/disabled purposes
-
Vendor Management
- List all vendors
- Check specific vendor consent
- Enable/Disable individual vendors
- Get enabled/disabled vendors
-
UI Integration
- Multiple UI strategies (Popup, Dialog, Activity, Fragment)
- Customizable layouts
- WebView integration
- Dark mode support
// Basic initialization
CmpManager.createInstance(
context = context,
codeId = "Your Code-ID goes here (13 characters)",
serverDomain = "delivery.consentmanager.net",
appName = "CMPSDKv2DemoApp",
lang = "en"
)
// With callbacks
CmpManager.createInstance(
context = context,
config = CmpConfig.apply {
id = "Your Code-ID"
domain = "delivery.consentmanager.net"
appName = "CMPSDKv2DemoApp"
language = "en"
},
openListener = OnOpenCallback { /* Handle open */ },
closeListener = OnCloseCallback { /* Handle close */ },
errorCallback = OnErrorCallback { error, message -> /* Handle error */ }
)
// Basic initialization
CmpManager.createInstance(
context,
"Your Code-ID goes here (13 characters)",
"delivery.consentmanager.net",
"CMPSDKv2DemoApp",
"en"
);
// With callbacks
CmpManager.createInstance(
context,
CmpConfig.INSTANCE.apply(config -> {
config.setId("Your Code-ID");
config.setDomain("delivery.consentmanager.net");
config.setAppName("CMPSDKv2DemoApp");
config.setLanguage("en");
return Unit.INSTANCE;
}),
() -> { /* Handle open */ },
() -> { /* Handle close */ },
(error, message) -> { /* Handle error */ },
null
);
val cmpManager = CmpManager.getInstance(context)
// Check if user has made a choice
val hasConsent = cmpManager.hasConsent()
// Accept all consents
cmpManager.acceptAll {
// Handle completion
}
// Reject all consents
cmpManager.rejectAll {
// Handle completion
}
// Open consent layer
cmpManager.openConsentLayer(context)
// Check if consent is required
cmpManager.checkConsentIsRequired(
OnCheckIsConsentRequired { required ->
// Handle result
}
)
CmpManager cmpManager = CmpManager.getInstance(context);
// Check if user has made a choice
boolean hasConsent = cmpManager.hasConsent();
// Accept all consents
cmpManager.acceptAll(() -> {
// Handle completion
});
// Reject all consents
cmpManager.rejectAll(() -> {
// Handle completion
});
// Open consent layer
cmpManager.openConsentLayer(context);
// Check if consent is required
cmpManager.checkConsentIsRequired(
required -> {
// Handle result
}
);
The SDK supports multiple UI presentation strategies:
- Popup Window
- Dialog
- Full Activity
- Fragment
Configure the UI appearance using CmpUIConfig
:
CmpUIConfig.apply {
// Configure as fullscreen
configureFullScreen()
// Or as bottom sheet
configureHalfScreenBottom(context)
// Or as centered dialog
configureCenterScreen(context)
// Customize behavior
isFocusable = true
isOutsideTouchable = false
windowAnimations = R.style.WindowAnimation
}
The SDK provides comprehensive callback interfaces:
OnOpenCallback
: Consent layer openedOnCloseCallback
: Consent layer closedOnErrorCallback
: Error occurredOnButtonClickedCallback
: User interaction eventsOnNotOpenedCallback
: Layer not shownCmpGoogleAnalyticsInterface
: Google consent mode updates
- Android SDK 21 or later
- AndroidX compatibility
- WebView support in the target device
This demo app is designed to showcase the integration patterns and available features of the CMP SDK. In a production environment, you would need to:
- Add proper error handling
- Implement persistence if required
- Add proper loading states
- Handle edge cases
- Add proper logging
- Consider configuration changes
- Handle WebView availability