DeviceCapture


public final class DeviceCapture


Summary

Public methods

static final @NonNull Bitmap

Captures an image of the device's screen into a Bitmap.

Public methods

takeScreenshot

public static final @NonNull Bitmap takeScreenshot()

Captures an image of the device's screen into a Bitmap.

This is essentially a wrapper for UIAutomation#takeScreenshot() that attempts to get a stable screenshot by forcing all the current application's root window views to redraw, and also handles cases where hardware renderer drawing is disabled.

This API is intended for use cases like debugging where an image of the entire screen is needed. For use cases where the image will be used for validation, its recommended to take a more isolated, targeted screenshot of a specific view or compose node. See androidx.test.core.view.captureToBitmap, androidx.test.espresso.screenshot.captureToBitmap and androidx.compose.ui.test.captureToImage.

This API does not support concurrent usage.

This API is currently experimental and subject to change or removal.

Returns
@NonNull Bitmap

a Bitmap that contains the image

Throws
kotlin.IllegalStateException

if called on the main thread. This is a limitation of connecting to UiAutomation, RuntimeException if UiAutomation fails to take the screenshot