MediaProjectionpublic final class MediaProjection extends Object 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 {@link
MediaProjectionManager#createScreenCaptureIntent}. This grants the ability to
capture screen contents, but not system audio.
|
Fields Summary |
---|
private static final String | TAG | private final android.media.projection.IMediaProjection | mImpl | private final android.content.Context | mContext | private final Map | mCallbacks |
Constructors Summary |
---|
public MediaProjection(android.content.Context context, android.media.projection.IMediaProjection impl)
mCallbacks = new ArrayMap<Callback, CallbackRecord>();
mContext = context;
mImpl = impl;
try {
mImpl.start(new MediaProjectionCallback());
} catch (RemoteException e) {
throw new RuntimeException("Failed to start media projection", e);
}
|
Methods Summary |
---|
public android.media.AudioRecord | createAudioRecord(int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)Creates an AudioRecord to capture audio played back by the system.
return null;
| public android.hardware.display.VirtualDisplay | createVirtualDisplay(java.lang.String name, int width, int height, int dpi, boolean isSecure, android.view.Surface surface, VirtualDisplay.Callback callback, android.os.Handler handler)
DisplayManager dm = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
int flags = isSecure ? DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE : 0;
return dm.createVirtualDisplay(this, name, width, height, dpi, surface,
flags | DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR |
DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION, callback, handler);
| public android.hardware.display.VirtualDisplay | createVirtualDisplay(java.lang.String name, int width, int height, int dpi, int flags, android.view.Surface surface, VirtualDisplay.Callback callback, android.os.Handler handler)Creates a {@link android.hardware.display.VirtualDisplay} to capture the
contents of the screen.
DisplayManager dm = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
return dm.createVirtualDisplay(
this, name, width, height, dpi, surface, flags, callback, handler);
| public android.media.projection.IMediaProjection | getProjection()Get the underlying IMediaProjection.
return mImpl;
| public void | registerCallback(android.media.projection.MediaProjection$Callback callback, android.os.Handler handler)Register a listener to receive notifications about when the {@link
MediaProjection} changes state.
if (callback == null) {
throw new IllegalArgumentException("callback should not be null");
}
if (handler == null) {
handler = new Handler();
}
mCallbacks.put(callback, new CallbackRecord(callback, handler));
| public void | stop()Stops projection.
try {
mImpl.stop();
} catch (RemoteException e) {
Log.e(TAG, "Unable to stop projection", e);
}
| public void | unregisterCallback(android.media.projection.MediaProjection$Callback callback)Unregister a MediaProjection listener.
if (callback == null) {
throw new IllegalArgumentException("callback should not be null");
}
mCallbacks.remove(callback);
|
|