Media projection

The media projection APIs introduced in Android 5 (API level 21) enable you to capture the contents of a device display as a media stream that you can play back, record, or cast to other devices, such as TVs.

A media projection involves three representations of the device display:

Real device display projected onto virtual display. Contents of
              virtual display written to application-provided `Surface`.
Figure 1. Real device display projected onto virtual display. Contents of virtual display written to application-provided Surface.

A media projection captures the contents of a device display and then projects the captured image to a virtual display that renders the image on a Surface.

The application provides the Surface by means of a SurfaceView or ImageReader, either of which consumes the contents of the captured display. The OnImageAvailableListener of an ImageReader enables you to manage images rendered on the Surface in real time. You can save the images as a recording or cast them to a TV or other device.


Begin a media projection session by obtaining a token that grants the app the ability to capture the display contents, device audio, or both. The token is represented by an instance of the MediaProjection class. You can create an instance of this class when you start a new activity.

Legacy approach

To acquire a media projection token using the legacy approach, call startActivityForResult() with an intent returned from the createScreenCaptureIntent() method of the MediaProjectionManager system service:





The call displays a confirmation dialog box informing the user that the media projection captures all displayed information, including any sensitive or personally identifiable information.

If the user provides confirmation, startActivityForResult() passes a result code and data to the onActivityResult() callback.

You can then pass the data and result code to the getMediaProjection() method from MediaProjectionManager to create an instance of MediaProjection:


mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, resultData)


mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, resultData);

The recommended approach for obtaining a media projection token uses APIs from the Jetpack Activity library:


val mediaProjectionManager = getSystemService(
var mediaProjection : MediaProjection

val startMediaProjection = registerForActivityResult(
) { result ->
  if (result.resultCode == RESULT_OK) {
    mediaProjection = mediaProjectionManager



final MediaProjectionManager mediaProjectionManager =
final MediaProjection[] mediaProjection = new MediaProjection[1];

ActivityResultLauncher<Intent> startMediaProjection = registerForActivityResult(
  new StartActivityForResult(),
  result -> {
    if (result.getResultCode() == Activity.RESULT_OK) {
      mediaProjection[0] = mediaProjectionManager
        .getMediaProjection(result.getResultCode(), result.getData());


Virtual display

The centerpiece of a media projection is the virtual display, which you create by calling createVirtualDisplay() on a MediaProjection instance:


virtualDisplay = mediaProjection.createVirtualDisplay(
                     null, null)


virtualDisplay = mediaProjection.createVirtualDisplay(
                     null, null);

The width and height parameters specify the width and height of the virtual display. To obtain values that match the width and height of the media projection, use the WindowMetrics APIs introduced in Android 11 (API level 30).


A media projection captures the entire display, regardless of whether the app creating the media projection is running full screen or in multi-window mode.

To get the dimensions of a media projection, use WindowManager#getMaximumWindowMetrics(), which returns a WindowMetrics object for the full display even if the media projection app is in multi-window mode, occupying only part of the display.

For compatibility down to API level 14, use WindowMetricsCalculator#computeMaximumWindowMetrics() from the Jetpack WindowManager library.

Call WindowMetrics#getBounds() to get the correct width and height for the media projection’s virtual display (see Virtual display).

Always make your media projection apps resizable. Resizable apps support device configuration changes and multi‑window mode (see Multi-window support).

If your app is not resizable, it must query the display bounds from a window context and retrieve the WindowMetrics of the maximum display area available to the app using WindowManager#getMaximumWindowMetrics():


val windowContext = context.createWindowContext(context.display!!,
      WindowManager.LayoutParams.TYPE_APPLICATION, null)
val projectionMetrics = windowContext.getSystemService(


Context windowContext = context.createWindowContext(context.getDisplay(),
      WindowManager.LayoutParams.TYPE_APPLICATION, null);
WindowMetrics projectionMetrics = windowContext.getSystemService(WindowManager.class)


You should size the media projection surface to produce output in the desired resolution. Make the size large (low resolution) for screen casting to TVs or computer monitors and small (high resolution) for device display recording.

As of 12L (API level 32), when the system renders a virtual display on the surface, it scales the virtual display to fit the surface using a process similar to the centerInside option from ImageView.

The new scaling approach improves screen casting to televisions and other large displays by maximizing the size of the surface image while ensuring the proper aspect ratio.


To get the best results with media projection, follow these recommendations:

  • Make your app resizable. Resizable apps support device configuration changes and multi-window mode (see Multi‑window support). In your app manifest, set resizeableActivity="true". On Android 7.0 (API level 24) and higher, this setting is true by default.
  • Enable your apps to support landscape and portrait orientations because both orientations are common across phone, tablet, and foldable form factors.
  • Use WindowManager#getMaximumWindowMetrics() to get the bounds of a media projection. For compatibility down to API level 14, use Jetpack WindowManager. (See the WindowMetrics section.)
  • If your app is not resizable, obtain the media projection bounds from a window context. (See the WindowMetrics section.)

Additional resources

For more information about media projection, see Capture video and audio playback.