FileDocCategorySizeDatePackage
MediaProjection.javaAPI DocAndroid 5.1 API7472Thu Mar 12 22:22:30 GMT 2015android.media.projection

MediaProjection

public 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)

hide


      
         
        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.AudioRecordcreateAudioRecord(int sampleRateInHz, int channelConfig, int audioFormat, int bufferSizeInBytes)
Creates an AudioRecord to capture audio played back by the system.

hide

        return null;
    
public android.hardware.display.VirtualDisplaycreateVirtualDisplay(java.lang.String name, int width, int height, int dpi, boolean isSecure, android.view.Surface surface, VirtualDisplay.Callback callback, android.os.Handler handler)

hide

        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.VirtualDisplaycreateVirtualDisplay(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.

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

        DisplayManager dm = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
        return dm.createVirtualDisplay(
                    this, name, width, height, dpi, surface, flags, callback, handler);
    
public android.media.projection.IMediaProjectiongetProjection()
Get the underlying IMediaProjection.

hide

        return mImpl;
    
public voidregisterCallback(android.media.projection.MediaProjection$Callback callback, android.os.Handler handler)
Register a listener to receive notifications about when the {@link MediaProjection} changes state.

param
callback The callback to call.
param
handler The handler on which the callback should be invoked, or null if the callback should be invoked on the calling thread's looper.
see
#unregisterCallback

        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 voidstop()
Stops projection.

        try {
            mImpl.stop();
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to stop projection", e);
        }
    
public voidunregisterCallback(android.media.projection.MediaProjection$Callback callback)
Unregister a MediaProjection listener.

param
callback The callback to unregister.
see
#registerCallback

        if (callback == null) {
            throw new IllegalArgumentException("callback should not be null");
        }
        mCallbacks.remove(callback);