startSharing

abstract fun startSharing(consent: Intent, callback: CompletionHandler<Void>, shareConfig: ShareConfig? = null)

Start content sharing on devices running API < 29 (Android 10).

Requirements:

  • The app must obtain a MediaProjection consent Intent using MediaProjectionManager.

  • Pass that consent Intent here in the same user flow.

Example: obtain MediaProjection consent Intent using the Activity Result API

// Ask the system for screen capture permission
val projectionManager = context.getSystemService(MediaProjectionManager::class.java)
val consentIntent = projectionManager.createScreenCaptureIntent()

// Launch the permission activity and handle the result
val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
// Pass the consent intent to start screen sharing
call.startSharing(result.data!!, CompletionHandler { /* handle result */})
}
}
launcher.launch(consentIntent)

Behavior:

  • If the consent Intent is invalid, the callback receives an error and sharing will not start.

  • When sharing stops (manually or on call end), resources are released so you can start again.

Since

3.16.0

Parameters

consent

MediaProjection consent Intent from the system activity result

callback

Completion callback (success or error)

shareConfig

Optional sharing optimization and audio capture configuration


abstract fun startSharing(notification: Notification?, notificationId: Int, consent: Intent, callback: CompletionHandler<Void>, shareConfig: ShareConfig? = null)

Start content sharing on devices running API >= 29 (Android 10+) with a foreground notification.

Requirements:

  • A valid foreground Notification (channel configured) and positive notificationId.

  • The app must obtain a MediaProjection consent Intent using MediaProjectionManager and pass it here.

Example: obtain MediaProjection consent Intent using the Activity Result API

val projectionManager = context.getSystemService(MediaProjectionManager::class.java)
val consentIntent = projectionManager.createScreenCaptureIntent()
val launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK && result.data != null) {
val consent = result.data!!
// Then call this API with your foreground notification
call.startSharing(notification = yourForegroundNotification,
notificationId = YOUR_NOTIFICATION_ID,
consent = consent,
callback = CompletionHandler { /* handle result */})
}
}
launcher.launch(consentIntent)

Behavior:

  • If the notification is invalid or consent is invalid, the callback receives an error.

  • When sharing stops (manually or on call end), resources are released so you can start again.

Since

3.16.0

Parameters

notification

Foreground notification shown while sharing

notificationId

Notification ID (positive integer)

consent

MediaProjection consent Intent from the system activity result

callback

Completion callback (success or error)

shareConfig

Optional sharing optimization and audio capture configuration