Installation
Add the dependency to your module’sbuild.gradle.kts:
INTERNET permission (declared in its manifest — no action needed).
How the pieces fit together
1
Initialize the client
Create a
Gravity instance with your API key, a Context, and production = true.2
Collect context & fetch ads
Call
gravity.getAds(...) with the conversation messages, session ID, and placements. The SDK auto-collects device signals (UA, OS, screen, timezone). Run it in parallel with your LLM call using coroutines.3
Render
Use the built-in
GravityAd Compose composable, GravityAdView (Views), or render the ad data yourself. Impression tracking fires automatically.Quick start
Constructor
getAds()
Placements
Jetpack Compose — render ads
SpecAd automatically handles the Gravity-managed placement design, safe fallback, impression and click tracking, required ad disclosure, images, and server-requested feedback controls.
Android Views
For XML-based layouts, useGravityAdView:
Custom rendering
If you render ads with your own UI, fire tracking manually:PII hashing
Hash email and phone for attribution without sending raw values:Ad feedback
Full example — parallel with LLM stream
FAQ
Does the ad request block my LLM response?
Does the ad request block my LLM response?
No. Use
async to fire getAds() in parallel with your LLM stream. It never throws — failures return an empty list.Does the SDK collect the Advertising ID (GAID)?
Does the SDK collect the Advertising ID (GAID)?
No. The SDK does not access Google Advertising ID. If you have user consent, pass it as
extraDeviceFields = mapOf("ifa" to gaid).What Android versions are supported?
What Android versions are supported?
Android 7.0+ (API 24+).
What dependencies does the SDK add?
What dependencies does the SDK add?
OkHttp for networking and Kotlin Coroutines. Compose dependencies are
compileOnly — only pulled in if your app already uses Compose.
