MediaProjection

class MediaProjection
kotlin.Any
   ↳ android.media.projection.MediaProjection

A token granting applications the ability to capture screen contents and/or record system audio. The exact capabilities granted depend on the type of MediaProjection.

A screen capture session can be started through . This grants the ability to capture screen contents, but not system audio.


Requires API level 21 (Android 5.0, Lollipop)

Summary

Nested classes
abstract

Callbacks for the projection session.

Public methods
Unit

Stops projection.

Unit

Register a listener to receive notifications about when the changes state.

Unit

Unregister a MediaProjection listener.

VirtualDisplay!
createVirtualDisplay(name: String, width: Int, height: Int, dpi: Int, flags: Int, surface: Surface?, callback: VirtualDisplay.Callback?, handler: Handler?)

Creates a android.hardware.display.VirtualDisplay to capture the contents of the screen.

Public methods

stop

added in API level 21
fun stop(): Unit

Stops projection.
Requires API level 21 (Android 5.0, Lollipop)

registerCallback

added in API level 21
fun registerCallback(callback: MediaProjection.Callback!, handler: Handler!): Unit

Register a listener to receive notifications about when the changes state.
Requires API level 21 (Android 5.0, Lollipop)

Parameters
callback MediaProjection.Callback!: The callback to call.
handler MediaProjection.Callback!: The handler on which the callback should be invoked, or null if the callback should be invoked on the calling thread's looper.

unregisterCallback

added in API level 21
fun unregisterCallback(callback: MediaProjection.Callback!): Unit

Unregister a MediaProjection listener.
Requires API level 21 (Android 5.0, Lollipop)

Parameters
callback MediaProjection.Callback!: The callback to unregister.

createVirtualDisplay

added in API level 21
fun createVirtualDisplay(name: String, width: Int, height: Int, dpi: Int, flags: Int, surface: Surface?, callback: VirtualDisplay.Callback?, handler: Handler?): VirtualDisplay!

Creates a android.hardware.display.VirtualDisplay to capture the contents of the screen.
Requires API level 21 (Android 5.0, Lollipop)

Parameters
name String: The name of the virtual display, must be non-empty. This value must never be null.
width String: The width of the virtual display in pixels. Must be greater than 0.
height String: The height of the virtual display in pixels. Must be greater than 0.
dpi String: The density of the virtual display in dpi. Must be greater than 0.
surface String: The surface to which the content of the virtual display should be rendered, or null if there is none initially. This value may be null.
flags String: A combination of virtual display flags. See DisplayManager for the full list of flags.
callback String: Callback to call when the virtual display's state changes, or null if none. This value may be null.
handler String: The android.os.Handler on which the callback should be invoked, or null if the callback should be invoked on the calling thread's main android.os.Looper. This value may be null.