# Screen share - Android

In this guide we'll use the [Screen Capturer quickstart](https://github.com/twilio/video-quickstart-android/tree/master/exampleScreenCapturer) to demonstrate how to share your Android device application screen with other participants connected to a Room using the MediaProjection API.

If you are interested in capturing from an Android View in the View hierarchy instead of capturing from the device screen you can take a look at our [custom video capturer example](https://github.com/twilio/video-quickstart-android/tree/master/exampleCustomVideoCapturer) instead:

## Using the Screen Capturer API

The [ScreenCapturer](https://sdk.twilio.com/android/video/latest/docs/) class that ships with the [Video Android SDK](/docs/video/android#add-the-sdk) is used to provide video frames for a [LocalVideoTrack](https://sdk.twilio.com/android/video/releases/7.9.1/docs/com/twilio/video/LocalVideoTrack.html) from a device's screen. The frames are provided via the `MediaProjection` API.

### Setup your app Manifest

Developers are required to specify a [foreground service](https://developer.android.com/about/versions/10/features#fg-service-types) when using the `MediaProjection` API. Reference the following snippet from the quickstart example `AndroidManifest.xml`.

```bash
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application>
    <service
        android:enabled="true"
        android:name=".ScreenCapturerService"
        android:foregroundServiceType="mediaProjection">
    </service>
</application>
```

### Initialize a Video View

```bash
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screen_capturer);
        localVideoView = findViewById(R.id.local_video);
    }
```

### Request screen share permission from user

Get an instance of the [MediaProjectionManager](https://developer.android.com/reference/android/media/projection/MediaProjectionManager.html) service. Call the `createScreenCaptureIntent` method in a new activity. This initiates a prompt dialog for the user to confirm screen projection.

### Request Screen Capturer Permission

```bash
    private void requestScreenCapturePermission() {
        Log.d(TAG, "Requesting permission to capture screen");
        MediaProjectionManager mediaProjectionManager = (MediaProjectionManager)
                getSystemService(Context.MEDIA_PROJECTION_SERVICE);

        // This initiates a prompt dialog for the user to confirm screen projection.
        startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(),
                REQUEST_MEDIA_PROJECTION);
    }
```

### Start screen share when permission received

Initialize the `ScreenCapturer` class, after permission is received from the user. Create the [LocalVideoTrack](https://sdk.twilio.com/android/video/releases/7.9.1/docs/com/twilio/video/LocalVideoTrack.html) object and pass the `ScreenCapturer` object to pass the captured local video frames. Set the `VideoView` object to `Visible` . Call the `addSink` method on the `LocalVideoTrack` object. Pass the `VideoView` object to begin receiving the screen capture video.

### Using the Screen Capturer Class

```bash
    private void startScreenCapture() {
        screenVideoTrack = LocalVideoTrack.create(this, true, screenCapturer);
        screenCaptureMenuItem.setIcon(R.drawable.ic_stop_screen_share_white_24dp);
        screenCaptureMenuItem.setTitle(R.string.stop_screen_share);

        localVideoView.setVisibility(View.VISIBLE);
        screenVideoTrack.addSink(localVideoView);
    }
```

Found an error ? Open an [issue on Github](https://github.com/twilio/video-quickstart-android/tree/master/exampleScreenCapturer)

Stuck on something? Can't find what you're looking for? Don't hesitate to contact Twilio Support through the [Console](https://console.twilio.com) or [Help Center](https://help.twilio.com) and we'll happily give you a hand.
