FileDocCategorySizeDatePackage
MediaProjectionManager.javaAPI DocAndroid 5.1 API7043Thu Mar 12 22:22:30 GMT 2015android.media.projection

MediaProjectionManager

public final class MediaProjectionManager extends Object
Manages the retrieval of certain types of {@link MediaProjection} tokens.

Get an instance of this class by calling {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()} with the argument {@link android.content.Context#MEDIA_PROJECTION_SERVICE}.

Fields Summary
private static final String
TAG
public static final String
EXTRA_APP_TOKEN
public static final String
EXTRA_MEDIA_PROJECTION
public static final int
TYPE_SCREEN_CAPTURE
public static final int
TYPE_MIRRORING
public static final int
TYPE_PRESENTATION
private android.content.Context
mContext
private Map
mCallbacks
private IMediaProjectionManager
mService
Constructors Summary
public MediaProjectionManager(android.content.Context context)

hide


      
       
        mContext = context;
        IBinder b = ServiceManager.getService(Context.MEDIA_PROJECTION_SERVICE);
        mService = IMediaProjectionManager.Stub.asInterface(b);
        mCallbacks = new ArrayMap<>();
    
Methods Summary
public voidaddCallback(android.media.projection.MediaProjectionManager$Callback callback, android.os.Handler handler)
Add a callback to monitor all of the {@link MediaProjection}s activity. Not for use by regular applications, must have the MANAGE_MEDIA_PROJECTION permission.

hide

        if (callback == null) {
            throw new IllegalArgumentException("callback must not be null");
        }
        CallbackDelegate delegate = new CallbackDelegate(callback, handler);
        mCallbacks.put(callback, delegate);
        try {
            mService.addCallback(delegate);
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to add callbacks to MediaProjection service", e);
        }
    
public android.content.IntentcreateScreenCaptureIntent()
Returns an Intent that must passed to startActivityForResult() in order to start screen capture. The activity will prompt the user whether to allow screen capture. The result of this activity should be passed to getMediaProjection.

        Intent i = new Intent();
        i.setClassName("com.android.systemui",
                "com.android.systemui.media.MediaProjectionPermissionActivity");
        return i;
    
public MediaProjectionInfogetActiveProjectionInfo()
Get the {@link MediaProjectionInfo} for the active {@link MediaProjection}.

hide

        try {
            return mService.getActiveProjectionInfo();
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to get the active projection info", e);
        }
        return null;
    
public MediaProjectiongetMediaProjection(int resultCode, android.content.Intent resultData)
Retrieve the MediaProjection obtained from a succesful screen capture request. Will be null if the result from the startActivityForResult() is anything other than RESULT_OK.

param
resultCode The result code from {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
param
resultData The resulting data from {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}

        if (resultCode != Activity.RESULT_OK || resultData == null) {
            return null;
        }
        IBinder projection = resultData.getIBinderExtra(EXTRA_MEDIA_PROJECTION);
        if (projection == null) {
            return null;
        }
        return new MediaProjection(mContext, IMediaProjection.Stub.asInterface(projection));
    
public voidremoveCallback(android.media.projection.MediaProjectionManager$Callback callback)
Remove a MediaProjection monitoring callback.

hide

        if (callback == null) {
            throw new IllegalArgumentException("callback must not be null");
        }
        CallbackDelegate delegate = mCallbacks.remove(callback);
        try {
            if (delegate != null) {
                mService.removeCallback(delegate);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to add callbacks to MediaProjection service", e);
        }
    
public voidstopActiveProjection()
Stop the current projection if there is one.

hide

        try {
            mService.stopActiveProjection();
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to stop the currently active media projection", e);
        }