Share via


MediaProjectionManager.GetMediaProjection(Int32, Intent) Method

Definition

Retrieves the MediaProjection obtained from a successful screen capture request.

[Android.Runtime.Register("getMediaProjection", "(ILandroid/content/Intent;)Landroid/media/projection/MediaProjection;", "")]
public Android.Media.Projection.MediaProjection? GetMediaProjection (int resultCode, Android.Content.Intent resultData);
[<Android.Runtime.Register("getMediaProjection", "(ILandroid/content/Intent;)Landroid/media/projection/MediaProjection;", "")>]
member this.GetMediaProjection : int * Android.Content.Intent -> Android.Media.Projection.MediaProjection

Parameters

resultCode
Int32

The result code from Activity#onActivityResult(int, int, Intent) onActivityResult(int, int, Intent).

resultData
Intent

The result data from Activity#onActivityResult(int, int, Intent) onActivityResult(int, int, Intent).

Returns

The media projection obtained from a successful screen capture request, or null if the result of the screen capture request is not Activity#RESULT_OK RESULT_OK.

Attributes

Remarks

Retrieves the MediaProjection obtained from a successful screen capture request. The result code and data from the request are provided by overriding Activity#onActivityResult(int, int, Intent) onActivityResult(int, int, Intent), which is called after starting an activity using #createScreenCaptureIntent().

Starting from Android android.os.Build.VERSION_CODES#R R, if your application requests the android.Manifest.permission#SYSTEM_ALERT_WINDOW SYSTEM_ALERT_WINDOW permission, and the user has not explicitly denied it, the permission will be automatically granted until the projection is stopped. The permission allows your app to display user controls on top of the screen being captured.

An app targeting SDK version android.os.Build.VERSION_CODES#Q Q or later must invoke getMediaProjection and maintain the capture session (MediaProjection#createVirtualDisplay(String, int, int, int, int, Surface, android.hardware.display.VirtualDisplay.Callback, Handler) MediaProjection#createVirtualDisplay) while running a foreground service. The app must set the android.R.attr#foregroundServiceType foregroundServiceType attribute to android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION in the <c>&amp;lt;service&amp;gt;</c> element of the app's manifest file.

For an app targeting SDK version android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE U or later, the user must have granted the app with the permission to start a projection, before the app starts a foreground service with the type android.content.pm.ServiceInfo#FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION. Additionally, the app must have started the foreground service with that type before calling this API here, or else it'll receive a SecurityException from this API call, unless it's a privileged app. Apps can request the permission via the #createScreenCaptureIntent() and Activity#startActivityForResult(Intent, int) (or similar APIs).

Java documentation for android.media.projection.MediaProjectionManager.getMediaProjection(int, android.content.Intent).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to