Screen sharing


The Video SDK enables an app to live stream the contents of the device's screen to the session. This feature enhances the collaborative experience of a session by allowing a user to share their content on their Android device's screen.

To follow along with this section, you should have a basic understanding of Android Services. If you are not familiar with Services, Notifications, and foreground services, we strongly recommend that you take some time to learn about them before proceeding with this section. Here are some useful links explaining services and other concepts covered in this section:

On This Page

Obtain Permission to Capture Screen Content

Before using the SDK's built-in functionality for screen sharing, you must first request permission through Android's Media Projection Manager. To do so, add the following code to your Activity:


// Obtain the screen capture Intent through the MediaProjectionManager
MediaProjectionManager manager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
if (manager != null) {
    Intent intent = manager.createScreenCaptureIntent();
    // Pass the intent and a code unique to your application here
    startActivityForResult(intent, 0);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // Verify that this is the same request you sent earlier and that it was successful
    if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
        startScreenShare(data);
    }
}
private void startScreenShare(Intent data) {
    Intent intent = new Intent(this, YourNotificationService.class);
    ZoomVideoSDKShareHelper shareHelper = ZoomVideoSDK.getInstance().getShareHelper();
    // For Android O and newer, you must start a foreground service
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        startForegroundService(intent);
    } else {
        startService(intent);
    }
    shareHelper.startShareScreen(data);
}

// Obtain the screen capture Intent through the MediaProjectionManager
val manager = getSystemService(Context.MEDIA_PROJECTION_SERVICE) as? MediaProjectionManager
manager?.createScreenCaptureIntent()?.let {
    // Pass the intent and a code unique to your application here
    startActivityForResult(it, 0)
}
// Implement this to listen for the result of your request
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    // Verify that this is the same request you sent earlier and that it was successful
    if (requestCode == 0 && resultCode == Activity.RESULT_OK) {
        startScreenShare(data)
    }
}
private fun startScreenShare(data: Intent?) {
    val intent = Intent(this, YourNotificationService::class.java)
    val shareHelper = ZoomVideoSDK.getInstance().shareHelper
    // For Android O and newer, you must start a foreground service
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        startForegroundService(intent)
    } else {
        startService(intent)
    }
    shareHelper.startShareScreen(data)
}

If you are running Android O or higher, you must first implement a Service to be run as a foreground service before starting the screen share. Foreground services require a notification, which also requires a notification channel as of Android O. The following code can be run from within the onCreate method of your Service:


String channelId = “SomeUniqueString”;
// Create a builder for your notification with a unique String for the channelId
// Recommended: store the channel ID as a top-level constant within your Service class
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext(), channelId)
    .setAutoCancel(false)
    .setOngoing(true)
    .setContentText(“Screen Share”);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Device is running a version that requires a notification channel
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    if (manager != null && manager.getNotificationChannel(channelId == null)) {
        // Your notification channel has not been created yet
        manager.createNotificationChannel(channelId);
    }
    int id = 0; // Define some ID for your notification
    startForeground(id, builder.build());
}

val channelId = “SomeUniqueString”
// Create a Builder for your notification with a unique String for the channelId
// Recommended: store the channel ID as a top-level constant within your Service class
val builder = NotificationCompat.Builder(applicationContext, channelId).apply {
    setAutoCancel(false)
    setOngoing(true)
    setContentText(“Screen Share”)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    // Device is running a version that requires a notification channel
    (getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager)?.let {
        if (it.getNotificationChannel(channelId) == null) {
            // Your notification channel has not been created yet
            it.createNotificationChannel(channelId)
        }
    }
    val id = 0 // Define some ID for your notification
    startForeground(id, builder.build())
}

After implementing your Service, don't forget to declare it in your AndroidManifest.xml file within the application element:

<service
    android:name=”.YourService”
    android:foregroundServiceType="mediaProjection" />

Verify Screen Share

After successfully completing the above steps to share your screen, you can verify that your screen share is visible on another device by responding to the following callback within your ZoomVideoSDKDelegate:


@Override
public void onUserShareStatusChanged(ZoomVideoSDKShareHelper shareHelper, ZoomVideoSDKUser userInfo, ZoomVideoSDKShareStatus status)

override fun onUserShareStatusChanged(shareHelper: ZoomVideoSDKShareHelper?, userInfo: ZoomVideoSDKUser?, status: ZoomVideoSDKShareStatus?)

Next Steps

Need help?

If you're looking for help, try Developer Support or our Developer Forum. Priority support is also available with Premier Developer Support plans.