# Screenshot

Summary:[Ctors](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#pubctors)\|[Methods](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#)  

# Screenshot

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
Screenshot
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|---------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.runner.screenshot.Screenshot |

<br />

*** ** * ** ***

The Screenshot instance provides methods to capture a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)during instrumentation tests run on an android device.

The Screenshot instance keeps track of a set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s that will be passed to each[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)object when they are created during any test. These[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s are capable of processing the[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that was created.

**This API is currently in beta.**

## Summary

|                                                     ### Public constructors                                                     ||
|------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Screenshot](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#Screenshot())`() ` |

|                                                                                                                                                                                                                                                                                                                                                                                                                                              ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                              ||
|-------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void`                                                                                                          | ` `[addScreenCaptureProcessors](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#addScreenCaptureProcessors(java.util.Set<android.support.test.runner.screenshot.ScreenCaptureProcessor>))`(`[Set](https://developer.android.com/reference/java/util/Set.html)`<`[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)`> screenCaptureProcessors) ` Adds the given set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to the current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s. |
| ` static `[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | ` `[capture](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#capture(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity.html)` activity) ` Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the given activity's root[View](https://developer.android.com/reference/android/view/View.html)hierarchy content.                                                                                                                                                                                                          |
| ` static `[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | ` `[capture](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#capture())`() ` Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the visible screen content for Build.VERSION_CODES.JELLY_BEAN_MR2 and above.                                                                                                                                                                                                                                                                                                                                                           |
| ` static `[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | ` `[capture](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#capture(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` view) ` Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the given view's hierarchy content.                                                                                                                                                                                                                                                                                                      |
| ` static void`                                                                                                          | ` `[setScreenshotProcessors](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#setScreenshotProcessors(java.util.Set<android.support.test.runner.screenshot.ScreenCaptureProcessor>))`(`[Set](https://developer.android.com/reference/java/util/Set.html)`<`[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)`> screenCaptureProcessors) ` Sets the current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to the given set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s.       |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public constructors

### Screenshot

```
Screenshot ()
```

<br />

<br />

## Public methods

### addScreenCaptureProcessors

```
void addScreenCaptureProcessors (Set<ScreenCaptureProcessor> screenCaptureProcessors)
```

Adds the given set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to the current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s.

The current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s will be passed to each[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that is created.

<br />

|                                                                                         Parameters                                                                                         ||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `screenCaptureProcessors` | `Set`: the set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to add <br /> |

### capture

```
ScreenCapture capture (Activity activity)
```

Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the given activity's root[View](https://developer.android.com/reference/android/view/View.html)hierarchy content.

The[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that is returned will also contain the set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s that have been set in this instance.

<br />

|                                                                                                                                              Parameters                                                                                                                                               ||
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `activity` | `Activity`: the[Activity](https://developer.android.com/reference/android/app/Activity.html)who's root[View](https://developer.android.com/reference/android/view/View.html)will be used to create a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html) <br /> |

|                                                                                                                                                                             Returns                                                                                                                                                                              ||
|---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains the bitmap of the given activity's root[View](https://developer.android.com/reference/android/view/View.html). <br /> |

|                                                                       Throws                                                                        ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if given activity is null                      |
|                                                                                                     | If there was an error capturing the screenshot |
| `Screenshot.ScreenShotException`                                                                    |                                                |

### capture

```
ScreenCapture capture ()
```

Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the visible screen content for Build.VERSION_CODES.JELLY_BEAN_MR2 and above.

The[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that is returned will also contain the set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s that have been set in this instance.

Note: Only use this method if all your tests run on API versions Build.VERSION_CODES.JELLY_BEAN_MR2 or above. If you need to take screenshots on lower API levels, you need to use[capture(Activity)](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#capture(android.app.Activity))or[capture(View)](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot#capture(android.view.View))for those versions.

<br />

|                                                                                                                                           Returns                                                                                                                                           ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains the bitmap of the visible screen content. <br /> |

|                                                                             Throws                                                                             ||
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
| [IllegalStateException](https://developer.android.com/reference/java/lang/IllegalStateException.html) | if used on API below Build.VERSION_CODES.JELLY_BEAN_MR2 |
|                                                                                                       | If there was an error capturing the screenshot          |
| `Screenshot.ScreenShotException`                                                                      |                                                         |

### capture

```
ScreenCapture capture (View view)
```

Creates a[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of the given view's hierarchy content.

The[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that is returned will also contain the set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s that have been set in this instance.

<br />

|                                                                                         Parameters                                                                                          ||
|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `view` | `View`: the[View](https://developer.android.com/reference/android/view/View.html)to create a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)of <br /> |

|                                                                                                                                              Returns                                                                                                                                               ||
|---------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture) | [ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that contains the bitmap of the given view's hierarchy content. <br /> |

|                                                                       Throws                                                                        ||
|-----------------------------------------------------------------------------------------------------|------------------------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException.html) | if given view is null                          |
|                                                                                                     | If there was an error capturing the screenshot |
| `Screenshot.ScreenShotException`                                                                    |                                                |

### setScreenshotProcessors

```
void setScreenshotProcessors (Set<ScreenCaptureProcessor> screenCaptureProcessors)
```

Sets the current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to the given set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s.

The current set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s will be passed to each[ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)that is created.

<br />

|                                                                                         Parameters                                                                                         ||
|---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `screenCaptureProcessors` | `Set`: the set of[ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)s to use <br /> |

-

  ## Interfaces

  - [ScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCaptureProcessor)
-

  ## Classes

  - [BasicScreenCaptureProcessor](https://developer.android.com/reference/android/support/test/runner/screenshot/BasicScreenCaptureProcessor)
  - [ScreenCapture](https://developer.android.com/reference/android/support/test/runner/screenshot/ScreenCapture)
  - [Screenshot](https://developer.android.com/reference/android/support/test/runner/screenshot/Screenshot)
  - [UiAutomationWrapper](https://developer.android.com/reference/android/support/test/runner/screenshot/UiAutomationWrapper)