Getting started - Android
The OptSens SDK is a single Gradle dependency. Add it, call OptSens.configure
with your SDK ID, and show the banner. The same SDK runs on phone, tablet,
Android TV and Fire TV.
Requirements
- The SDK is available on the Pro, Business and Custom plans.
- Android 5.0 (API level 21) or higher.
- The SDK declares the
INTERNETpermission. You add nothing to your manifest for phone or tablet.
Get your SDK ID
- In your OptSens dashboard, click Add Domain in the top navigation and add this app. See Add your app for the full flow (choosing the platform, entering the app id, picking a plan).
- Run the guided onboarding. On the Integration step, copy your SDK ID. It is also on the dashboard Integration page at any time.
Add the SDK
The SDK is published on Maven Central. Add Maven Central to your repositories:
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
}
Add the dependency to your app module. It pulls the consent engine in for you:
// app/build.gradle.kts
dependencies {
implementation("com.optsens:optsens-ui:1.0.0")
}
Initialize OptSens
Call OptSens.configure once, early in an activity, with your SDK ID. Show the
banner when the visitor still needs to decide, and attach the floating button so
they can reopen their choice later:
import com.optsens.sdk.core.OptSens
import com.optsens.sdk.ui.OptSensBanner
import com.optsens.sdk.ui.OptSensWidget
OptSens.configure(this, "YOUR_SDK_ID") { result ->
result.onSuccess { status ->
if (status.shouldCollectConsent) {
OptSensBanner.showFirstLayer(this)
}
OptSensWidget.attach(this)
}
}
configure fetches your banner configuration, resolves the visitor's region and
writes the on-device consent keys. No Application subclass is required. Unlike
the web, the floating button is not injected for you: OptSensWidget.attach
mounts it (see Floating button).
Android TV and Fire TV
The same SDK runs on Android TV and Fire TV. To let one build install on both phone and TV, mark the touchscreen optional and declare leanback support in your manifest:
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />
The SDK detects the TV at runtime and shows the large-screen, remote-controlled banner with D-pad focus. See Connected TV for the details.
After integrating
- Run the app. The banner shows on first launch when consent is needed.
- Confirm the integration from the app's Verify step in the dashboard.
- Gate your own analytics and ad code with
OptSens.hasConsent, and forward consent to Google and your partners.
Next: Showing the banner.