Screenshot API Kotlin Android Guide 2026

Integrate SnapAPI into Android apps and Kotlin backends with OkHttp, Coroutines, WorkManager background jobs, and Coil image loading. Full Kotlin code examples.

Get Free API Key

Calling SnapAPI from Kotlin Android with OkHttp

Android applications call the SnapAPI REST endpoint using OkHttp, the standard HTTP client for Android. Create a SnapApiClient class that initializes an OkHttpClient with a sixty-second call timeout, builds the screenshot request URL using HttpUrl.Builder with the URL and format query parameters, adds the Authorization Bearer header using a Request.Builder, and executes the request using either the synchronous execute method inside a coroutine or the asynchronous enqueue method with a Callback. Use Kotlin coroutines with the Dispatchers.IO dispatcher for network operations: wrap the synchronous OkHttp execute call in withContext(Dispatchers.IO) to ensure it runs on the IO thread pool without blocking the main thread. Return the response bytes on success and throw a SnapApiException with the HTTP status code on error responses, allowing calling code to handle rate limits and invalid URL errors distinctly using a sealed class error hierarchy.

import okhttp3.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class SnapApiClient(private val apiKey: String) {
    private val client = OkHttpClient.Builder()
        .callTimeout(60, java.util.concurrent.TimeUnit.SECONDS)
        .build()

    suspend fun screenshot(
        url: String,
        fullPage: Boolean = false,
        format: String = "png"
    ): ByteArray = withContext(Dispatchers.IO) {
        val httpUrl = HttpUrl.Builder()
            .scheme("https")
            .host("api.snapapi.pics")
            .addPathSegment("screenshot")
            .addQueryParameter("url", url)
            .addQueryParameter("format", format)
            .addQueryParameter("full_page", fullPage.toString())
            .build()
        val request = Request.Builder()
            .url(httpUrl)
            .header("Authorization", "Bearer $apiKey")
            .build()
        val response = client.newCall(request).execute()
        if (!response.isSuccessful) {
            throw SnapApiException(response.code, response.message)
        }
        response.body!!.bytes()
    }
}

data class SnapApiException(val code: Int, val message: String)
    : Exception("SnapAPI error $code: $message")

Background Screenshot Processing with WorkManager

Android applications use WorkManager for reliable background screenshot generation that survives process death, device restarts, and Doze mode. Define a ScreenshotWorker class inheriting CoroutineWorker that receives the target URL and screenshot options as input data, calls SnapApiClient.screenshot, saves the result to the app file cache directory or uploads it to cloud storage, and stores the result file path or URL in the output data. Enqueue screenshot work using WorkManager.enqueue with a OneTimeWorkRequest built with the input data, a network required constraint to prevent the work from running without internet access, and an exponential backoff retry policy for handling transient SnapAPI errors. Observe the work status using the WorkInfo LiveData or Flow returned by WorkManager.getWorkInfoByIdLiveData in the ViewModel to display progress in the UI and navigate to the result when the work completes successfully.

Displaying Screenshots with Coil Image Loading

Android UI components display SnapAPI screenshot results using Coil, the Kotlin-first image loading library. After the ScreenshotWorker saves the screenshot to a file or uploads it to cloud storage, the result URL is observed by the ViewModel and set on an ImageView using the coil.load extension function with the screenshot URL as the parameter. Coil handles image loading, decoding, caching, and display with full coroutine support and a clean Kotlin DSL. For screenshots stored as files in the app cache, use the File URI with coil.load(File(screenshotPath)) to load directly from disk. For screenshots stored in cloud storage, load from the HTTPS CDN URL. Configure the Coil ImageLoader with a disk cache policy and a memory cache size appropriate for the number of screenshots displayed simultaneously in your app. Use the placeholder and error parameters in the coil.load call to display a loading skeleton while the screenshot loads and an error image if loading fails.

Get Started with SnapAPI in Kotlin

Add the OkHttp dependency to your Android project build.gradle, set the SNAP_API_KEY as a BuildConfig field from your local.properties file, and initialize SnapApiClient with BuildConfig.SNAP_API_KEY. For Kotlin backend applications using Ktor or Spring Boot, the same OkHttp-based client works without modification. Register at snapapi.pics/register for a free API key with two hundred requests per month and no credit card. The official SnapAPI Kotlin SDK at github.com/Sleywill/snapapi-kotlin provides a pre-built client compatible with both Android and Kotlin JVM backend applications, with typed response models and coroutine-native async methods.

Kotlin Screenshot API for iOS with Swift SDK

For teams building cross-platform mobile applications using Kotlin Multiplatform Mobile, SnapAPI integrates on the Android side via the Kotlin SDK and on the iOS side via the Swift SDK available at github.com/Sleywill/snapapi-swift. The screenshot use cases for mobile applications include displaying screenshot thumbnails of user-bookmarked URLs in a visual bookmark grid, capturing screenshots of web content the user is viewing for save-to-read-later features, and generating og:image previews when users share links from the app to social platforms. On Android, OkHttp with coroutines provides the HTTP client layer. On iOS with Swift, URLSession with async/await or the Alamofire HTTP client library provides an equivalent pattern. Both platforms store screenshot results in cloud storage and display them using platform-native image loading libraries, Coil on Android and Kingfisher or SDWebImage on iOS, caching the downloaded images in the library disk cache for fast repeat display without redundant network requests.

Android Screenshot API Background Sync Patterns

Android applications that pre-populate screenshot thumbnails for offline browsing implement background screenshot sync using WorkManager with periodic work requests. Define a PeriodicWorkRequest that runs daily with a network required constraint, iterating over the user bookmark list and calling SnapAPI for each bookmarked URL that does not have a cached screenshot or whose cached screenshot is older than the configured refresh interval. Store screenshot files in the app internal storage directory with the URL hash as the filename, using Android's File API for the storage operations. Check available storage space before each screenshot sync run and skip the sync if available space is below a minimum threshold to avoid filling the user device storage with screenshot files. Respect Android battery optimization by using WorkManager with the BATTERY_NOT_LOW constraint to avoid running screenshot sync when the device battery is low, and configure the periodic interval to at least fifteen minutes to comply with WorkManager's minimum periodic work interval. Display a notification when the screenshot sync job completes with new screenshots available, using Android's NotificationCompat API with a deep link to the bookmark list view where the new thumbnails are displayed.

Kotlin Screenshot API in Spring Boot Backend

Kotlin backend applications using Spring Boot integrate SnapAPI via the WebClient reactive HTTP client or the RestTemplate synchronous client. For coroutine-based Spring Boot applications using spring-boot-starter-webflux, WebClient with the awaitBody Kotlin extension provides a coroutine-native way to call the SnapAPI screenshot endpoint. Configure a WebClient bean with the SnapAPI base URL and Authorization header in the Spring configuration class, and inject it into a SnapApiService component that wraps the WebClient call in a suspend function. The same Spring Boot patterns described in the screenshot API Spring Boot guide apply to Kotlin services: register the SnapApiService as a component, use @Value to inject the API key from application.properties, and configure Polly resilience policies in the HttpClient builder for retry and circuit breaker behavior. Register at snapapi.pics/register for a free API key with two hundred requests per month to start your Kotlin screenshot integration today.

Android Screenshot API Error Handling and User Feedback

Android applications provide appropriate user feedback when SnapAPI screenshot generation fails or takes longer than expected. Display a loading indicator or skeleton placeholder in the ImageView while the screenshot loads asynchronously, replacing it with the real screenshot when the WorkManager job completes or the coroutine returns. When the SnapAPI call fails with a network error, display a retry button that re-enqueues the WorkManager screenshot job rather than showing a permanent error state, as transient network failures are common on mobile devices that switch between WiFi and cellular connectivity. When the SnapAPI call fails with an invalid URL error indicating the bookmarked URL is no longer accessible, display an error placeholder image and update the bookmark record with an error status, filtering error-status bookmarks out of the visual thumbnail grid or displaying them with a distinct error indicator. Implement a maximum retry count stored in the bookmark record to prevent indefinitely retrying permanently broken URLs that will never produce a successful screenshot. Register at snapapi.pics/register for a free API key to start your Android screenshot integration today.

The SnapAPI free tier provides two hundred requests per month with no credit card and no expiry, suitable for Android development environments and low-volume production applications. Register at snapapi.pics/register for your free API key. The official Kotlin SDK at github.com/Sleywill/snapapi-kotlin provides typed coroutine-native methods for all four endpoints compatible with Android API level 21 and above and Kotlin JVM backend applications, reducing integration to adding a Gradle dependency and setting the API key. Upgrade to the Starter plan at nineteen dollars per month for five thousand requests when your production Android application exceeds the free tier volume, with no code changes required to continue using the same SDK and API key after upgrading.