Skip to main content

Share a screen using Daily’s Android SDK

Screen sharing enables the local participant to display the contents of their screen to other users in the meeting. Before you begin, ensure that you understand how to start a video call. For details, see the Android Overview. This guide will describe how to implement screen sharing using the Android SDK, showing you some examples, and pointing you to where you can learn more.

How to start a screen share

The first task for the app is to request the MediaProjection permission activity. It must validate that the result code is Activity.RESULT_OK before calling the Daily SDK to initiate the screen sharing. Once the permission is granted, the daily-android SDK can be invoked to start screen sharing. The following code snippet shows how you might start a screen share:

// Create call client
val call = CallClient(applicationContext)

// initializing the mediaProjectionManager that we are going to use later to ask for the screen share intent
val mediaProjectionManager = getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManager

private val requestMediaProjection =
    registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
        if (result.resultCode == Activity.RESULT_OK) {
            // Once the permission is granted we can invoke the Daily SDK to start screen share
            val mediaProjectionPermissionResultData: Intent? = result.data
            if (mediaProjectionPermissionResultData != null) {
                // using the start screen share convenience method
                call.startScreenShare(mediaProjectionPermissionResultData)

                // Other possible approach is to use the updateInputs method.
                // In this case, first we need to set the media projection intent
                call.setScreenShareProjectionIntent(mediaProjectionPermissionResultData)
                // and later invoke to enable the screen video.
                call.updateInputs(InputSettingsUpdate(
                    screenVideo = ScreenVideoInputSettingsUpdate(
                        isEnabled = Enable(),
                    )
                ))
            }
        } else {
            Log.e(TAG, "Denied permission to start media projection.")
        }
    }

// Private method that must be invoked from the app to request permission and start screen share
private fun startScreenShare() {
    // Creating the intent and requesting permission to start screen share
    val mediaProjectionIntent = mediaProjectionManager.createScreenCaptureIntent()
    requestMediaProjection.launch(mediaProjectionIntent)
}


To confirm that screen sharing started, listen for onInputsUpdated event and check the property screenVideo.
To use screen sharing, a Foreground Service is required. This is needed because the app performs tasks that continue even when the app is not in the foreground. You can find more details about how to start a Foreground Service in our installation guide.

How to stop screen share

The following code snippet shows how you might stop a screen share:

// Create call client
val call = CallClient(applicationContext)

// using the stop screen share convenience method
call.stopScreenShare()

// Other possible approach is to use the updateInputs method.
call.updateInputs(InputSettingsUpdate(
    screenVideo = ScreenVideoInputSettingsUpdate(
        isEnabled = Disable(),
    )
))


How to check if the local screen sharing is enabled

The following code snippet shows how you might check if the local screen sharing is enabled:

// Create call client
val call = CallClient(applicationContext)

// checking if the local screen share is enabled
call.inputs().screenVideo.isEnabled

Demo app

To see a working example of how to interact with the Daily Client SDK for screen sharing, see our Android demo app.