# Screen sharing

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

This section describes how to add screen sharing functionality.

The Video SDK for Android and iOS provides two methods of screen sharing:

-   Sharing a single view with `appShareWithView` (not yet supported)
-   Broadcasting the entire screen

_**Currently `appShareWithView` is not supported by the Video SDK for Flutter.**_

## iOS only

For iOS, sharing the entire screen requires the use of a broadcast extension. See [Screen Sharing for Video SDK for iOS](/docs/video-sdk/ios/share/) for details. To broadcast the entire screen on iOS, follow the instructions to set up your environment to support broadcasting in [Broadcast the device screen for the Video SDK for iOS](/docs/video-sdk/ios/share/#broadcast-the-device-screen).

Once this has been done, continue with the steps below.

## For Android version 14 and later

Android version 14 and later require foreground service permission to start the screen sharing. `FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK` and `FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION` are required in the application. See the sample app for implementation details.

## iOS and Android

To screen share for Android and iOS, obtain an instance of the `ZoomVideoSDKShareHelper` object:

```dart
var shareHelper = await zoom.shareHelper;
```

Verify that no one else is currently sharing and that screen sharing is not locked by the host:

```dart
var isOtherSharing = await zoom.shareHelper.isOtherSharing();
var isShareLocked = await zoom.shareHelper.isShareLocked();

if (isOtherSharing) {
  showDialog<String>(
    context: context,
    builder: (BuildContext context) => AlertDialog(
      title: const Text("Error"),
      content: const Text('Other is sharing'),
      actions: <Widget>[
        TextButton(
          onPressed: () => Navigator.pop(context, 'OK'),
          child: const Text('OK'),
        ),
      ],
    ),
  );
} else if (isShareLocked) {
  showDialog<String>(
    context: context,
    builder: (BuildContext context) => AlertDialog(
      title: const Text("Error"),
      content: const Text('Share is locked by host'),
      actions: <Widget>[
        TextButton(
          onPressed: () => Navigator.pop(context, 'OK'),
          child: const Text('OK'),
        ),
      ],
    ),
  );
}
```

Call `shareScreen()` to begin sharing and `stopShare()` to stop sharing.

```dart
  if (isSharing.value) {
    zoom.shareHelper.stopShare();
  } else {
    zoom.shareHelper.shareScreen();
  }
```

Add the following callbacks in the app to track the screen sharing status.

```dart
var eventListener = ZoomVideoSdkEventListener();

final userShareStatusChangeListener = eventListener.addListener(EventType.onUserShareStatusChanged, (data) async {
  data = data as Map;
  ZoomVideoSdkUser? mySelf = await zoom.session.getMySelf();
  ZoomVideoSdkUser shareUser = ZoomVideoSdkUser.fromJson(jsonDecode(data['user'].toString()));
  ZoomVideoSdkShareAction? shareAction = ZoomVideoSdkShareAction.fromJson(jsonDecode(data['shareAction']));

  if (shareAction.shareStatus == ShareStatus.Start || shareAction.shareStatus == ShareStatus.Resume) {
    sharingUser.value = shareUser;
    fullScreenUser.value = shareUser;
    isSharing.value = (shareUser.userId == mySelf?.userId);
  } else {
    sharingUser.value = null;
    isSharing.value = false;
    fullScreenUser.value = mySelf;
  }
  userShareStatusFlag.value = !userShareStatusFlag.value;
});
```
