Skip to main content

Screen sharing

Introduction

The Stream Video Android SDK has support for screen sharing from an Android device. The SDK is using the Android Media Projection API for the capture.

In order for a user to be able to share their screen, they must have the screenshare capability configured for the call they are in.

How to start sharing your screen

You need to be in an active call (have a Call instance in Active call state) to start screen sharing.

You must ask the user for screen sharing permission before you can start sharing the screen. The permission is requested by using the Media Projection API. And then use the returned intent data from the permission result and call Call.startScreenSharing(intentData).

An example implementation:

val startMediaProjection = registerForActivityResult(StartActivityForResult()) { result ->
if (it.resultCode == Activity.RESULT_OK && it.data != null) {
call.startScreenSharing(it.data!!)
}
}

val mediaProjectionManager = context.getSystemService(MediaProjectionManager::class.java)
startMediaProjection.launch(mediaProjectionManager.createScreenCaptureIntent())

You can check if screen sharing is currently active by observing call.screenShare.isEnabled.

Stopping screen sharing

Screen sharing can be stopped wit Call.stopScreenSharing(). It is automatically stopped if the call state goes into Inactive state.

The user can also disable screen sharing directly in the system settings (depending on the OEM there is usually a button in the notification bar for disabling screen sharing).

And the screen sharing can also be disabled through the screen sharing notification action button (described in next section).

Screen sharing notification

A notification is always displayed to the user when the screen sharing is active. The notification itself can't be hidden and is required by the Android OS. The notification title and description can be customised.

Override string stream_video_screen_sharing_notification_title and stream_video_screen_sharing_notification_description to customise the notification text.

There is also a "Stop screen sharing" action button on the notification, the text of the button can be modified by overriding stream_video_screen_sharing_notification_action_stop.

All notifications in Android need to have a notification channel. The Stream Video Android SDK will automatically create a new channel for the screen sharing notification. You can customise the channel title and description (this is visible to the user in the system application settings). Override stream_video_screen_sharing_notification_channel_title and stream_video_screen_sharing_notification_channel_description.

<string name="stream_video_screen_sharing_notification_title">You are screen sharing</string>
<string name="stream_video_screen_sharing_notification_description"></string>
<string name="stream_video_screen_sharing_notification_action_stop">Stop screen sharing</string>
<string name="stream_video_screen_sharing_notification_channel_title">Screen-sharing</string>
<string name="stream_video_screen_sharing_notification_channel_description">Required to be enabled for screen sharing</string>

Did you find this page helpful?