Allscreenshots Docs
SDKs

Kotlin SDK

Use the Java SDK with Kotlin

Kotlin SDK

For Kotlin projects, use the Java SDK. The Java SDK works seamlessly with Kotlin and provides full compatibility with Kotlin's language features.

Source code: GitHub | Maven: com.allscreenshots.sdk:allscreenshots-sdk

Installation

Gradle (Kotlin DSL)

dependencies {
    implementation("com.allscreenshots.sdk:allscreenshots-sdk:1.0.0")
}

Gradle (Groovy)

dependencies {
    implementation 'com.allscreenshots.sdk:allscreenshots-sdk:1.0.0'
}

Quick start

import com.allscreenshots.sdk.AllscreenshotsClient
import com.allscreenshots.sdk.models.ScreenshotRequest
import java.io.File

fun main() {
    val client = AllscreenshotsClient.builder().build()

    val image = client.screenshots().capture(
        ScreenshotRequest.builder()
            .url("https://example.com")
            .device("Desktop HD")
            .fullPage(true)
            .build()
    )

    File("screenshot.png").writeBytes(image)
}

Configuration

val client = AllscreenshotsClient.builder()
    .apiKey("your-api-key")
    .baseUrl("https://api.allscreenshots.com")
    .timeout(Duration.ofSeconds(60))
    .maxRetries(3)
    .build()

Capture with options

val image = client.screenshots().capture(
    ScreenshotRequest.builder()
        .url("https://example.com")
        .device("Desktop HD")
        .format("png")
        .fullPage(true)
        .darkMode(true)
        .blockAds(true)
        .build()
)

Coroutines support

For async operations with Kotlin coroutines, you can wrap the SDK calls:

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

suspend fun captureScreenshot(url: String): ByteArray = withContext(Dispatchers.IO) {
    client.screenshots().capture(
        ScreenshotRequest.builder()
            .url(url)
            .build()
    )
}

Full documentation

For complete API documentation, configuration options, and advanced examples, see the Java SDK documentation.

On this page