Screenshot API for Kotlin: Android, JVM & Multiplatform
Integrate SnapAPI screenshot and scraping endpoints in Kotlin with OkHttp, Ktor Client, or the official Kotlin SDK. Works on Android, JVM, and multiplatform targets.
Screenshot API for Kotlin and Android
SnapAPI integrates seamlessly with Kotlin projects on Android, JVM backend services, and multiplatform builds. Whether you are generating open graph preview images from a Ktor backend, capturing competitor screenshots in a Spring Boot service, or building an Android utility app that renders remote pages, SnapAPI exposes a simple REST endpoint that any HTTP client can call. No native browser dependencies are required in your application.
Kotlin with OkHttp
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.File
val client = OkHttpClient()
val request = Request.Builder()
.url("https://api.snapapi.pics/v1/screenshot" +
"?url=https://example.com&full_page=true&format=png")
.header("X-Api-Key", "YOUR_API_KEY")
.build()
client.newCall(request).execute().use { response ->
if (response.isSuccessful) {
response.body?.bytes()?.let { bytes ->
File("screenshot.png").writeBytes(bytes)
println("Saved ${bytes.size} bytes")
}
} else {
println("Error: ${response.code}")
}
}OkHttp is the standard HTTP client on Android and widely used in JVM Kotlin services. The example above makes a synchronous call inside a use block to ensure the response body is properly closed. For Android applications, wrap this in a coroutine with Dispatchers.IO to keep the main thread free.
Kotlin Coroutines with Ktor Client
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
val client = HttpClient(CIO)
suspend fun captureScreenshot(url: String, apiKey: String): ByteArray {
val response: HttpResponse = client.get("https://api.snapapi.pics/v1/screenshot") {
parameter("url", url)
parameter("full_page", "true")
header("X-Api-Key", apiKey)
}
return response.readBytes()
}Ktor Client with the CIO engine is a lightweight, coroutine-native option for JVM and multiplatform targets. The suspend function integrates naturally with your existing coroutine scope, making it trivial to fire multiple screenshot requests concurrently with async and awaitAll.
Android Integration
On Android, add the OkHttp or Ktor dependencies to your build.gradle.kts and declare the internet permission in your manifest. For modern Android development with Jetpack Compose, fetch the screenshot bytes in a ViewModel using viewModelScope.launch, then load the result into an AsyncImage with Coil or convert the bytes to a Bitmap for display.
SnapAPI supports all core capture parameters from Android: viewport size via width and height, device emulation via device (30+ presets including Pixel 7, Galaxy S23, and iPad Air), full-page screenshots, custom CSS injection, and JavaScript execution before capture. This makes it practical to generate device-specific previews inside an Android app without bundling WebView hacks.
Using the Official Kotlin SDK
The official SnapAPI Kotlin SDK is available at github.com/Sleywill/snapapi-kotlin. It wraps the REST API with a type-safe DSL, handles authentication, and includes suspend functions for all endpoints: screenshot, scrape, extract, PDF, video, and AI analysis. Add it to your Gradle project and you can capture your first screenshot in three lines of Kotlin.
Sign up at snapapi.pics for 200 free captures per month. The free tier requires no credit card and supports all Kotlin integration patterns described above. Explore the full API reference at snapapi.pics/docs.html for complete parameter documentation covering every endpoint and response format.