# DeviceCapture

*** ** * ** ***


```
public final class DeviceCapture
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/test/core/app/DeviceCapture#takeScreenshot()()` Captures an image of the device's screen into a `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

## Public methods

### takeScreenshot

Artifact: [androidx.test:core](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/core/app/DeviceCapture.kt+function:takeScreenshot)

```
public static final @NonNull Bitmap takeScreenshot()
```

Captures an image of the device's screen into a `https://developer.android.com/reference/android/graphics/Bitmap.html`.

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 `https://developer.android.com/reference/androidx/test/core/view/package-summary#(android.view.View).captureToBitmap(android.graphics.Rect)`, androidx.test.espresso.screenshot.captureToBitmap and `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary.html`.

This API does not support concurrent usage.

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | a `https://developer.android.com/reference/android/graphics/Bitmap.html` that contains the image |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if called on the main thread. This is a limitation of connecting to UiAutomation, `https://developer.android.com/reference/java/lang/RuntimeException.html` if UiAutomation fails to take the screenshot |