Skip to main content

Installation

Add the dependency to your module’s build.gradle.kts:
The SDK requires 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()

The SDK auto-collects device signals (User-Agent, OS, model, screen size, timezone, locale, device type) and sends them with the request. Your dashboard’s Device and Geography breakdowns work automatically.
getAds() never throws. On any failure, it returns AdResult.EMPTY (empty ads list). Safe to fire-and-forget.

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, use GravityAdView:

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

No. Use async to fire getAds() in parallel with your LLM stream. It never throws — failures return an empty list.
No. The SDK does not access Google Advertising ID. If you have user consent, pass it as extraDeviceFields = mapOf("ifa" to gaid).
Android 7.0+ (API 24+).
OkHttp for networking and Kotlin Coroutines. Compose dependencies are compileOnly — only pulled in if your app already uses Compose.