public final class MediaProjection extends Object
A screen capture session can be started through MediaProjectionManager.createScreenCaptureIntent()
. This grants the ability to
capture screen contents, but not system audio.
Modifier and Type | Class and Description |
---|---|
static class |
MediaProjection.Callback
Callbacks for the projection session.
|
Constructor and Description |
---|
MediaProjection(Context context,
IMediaProjection impl) |
Modifier and Type | Method and Description |
---|---|
AudioRecord |
createAudioRecord(int sampleRateInHz,
int channelConfig,
int audioFormat,
int bufferSizeInBytes)
Creates an AudioRecord to capture audio played back by the system.
|
VirtualDisplay |
createVirtualDisplay(String name,
int width,
int height,
int dpi,
boolean isSecure,
Surface surface,
VirtualDisplay.Callback callback,
Handler handler) |
VirtualDisplay |
createVirtualDisplay(String name,
int width,
int height,
int dpi,
int flags,
Surface surface,
VirtualDisplay.Callback callback,
Handler handler)
Creates a
VirtualDisplay to capture the
contents of the screen. |
IMediaProjection |
getProjection()
Get the underlying IMediaProjection.
|
void |
registerCallback(MediaProjection.Callback callback,
Handler handler)
Register a listener to receive notifications about when the
MediaProjection changes state. |
void |
stop()
Stops projection.
|
void |
unregisterCallback(MediaProjection.Callback callback)
Unregister a MediaProjection listener.
|
public MediaProjection(Context context, IMediaProjection impl)
public void registerCallback(MediaProjection.Callback callback, Handler handler)
MediaProjection
changes state.callback
- The callback to call.handler
- The handler on which the callback should be invoked, or
null if the callback should be invoked on the calling thread's looper.unregisterCallback(android.media.projection.MediaProjection.Callback)
public void unregisterCallback(MediaProjection.Callback callback)
callback
- The callback to unregister.registerCallback(android.media.projection.MediaProjection.Callback, android.os.Handler)
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int dpi, boolean isSecure, Surface surface, VirtualDisplay.Callback callback, Handler handler)
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int dpi, int flags, Surface surface, VirtualDisplay.Callback callback, Handler handler)
VirtualDisplay
to capture the
contents of the screen.name
- The name of the virtual display, must be non-empty.width
- The width of the virtual display in pixels. Must be
greater than 0.height
- The height of the virtual display in pixels. Must be
greater than 0.dpi
- The density of the virtual display in dpi. Must be greater
than 0.surface
- The surface to which the content of the virtual display
should be rendered, or null if there is none initially.flags
- A combination of virtual display flags. See DisplayManager
for the full
list of flags.callback
- Callback to call when the virtual display's state
changes, or null if none.handler
- The Handler
on which the callback should be
invoked, or null if the callback should be invoked on the calling
thread's main Looper
.VirtualDisplay
public AudioRecord createAudioRecord(int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)
public void stop()
public IMediaProjection getProjection()