This documentation is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2026.
We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide to assist you in minimizing any service disruption.
In this guide we'll use the Screen Capturer quickstart to demonstrate how to share your Android device application screen with other participants connected to a Room using the MediaProjection API.
If you are interested in capturing from an Android View in the View hierarchy instead of capturing from the device screen you can take a look at our custom video capturer example instead:
The ScreenCapturer class that ships with the Video Android SDK is used to provide video frames for a LocalVideoTrack from a device's screen. The frames are provided via the MediaProjection
api.
Developers are required to specify a foreground service when using the MediaProjection
API. Reference the following snippet from the quickstart example AndroidManifest.xml
.
_10<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>_10_10<application>_10 <service_10 android:enabled="true"_10 android:name=".ScreenCapturerService"_10 android:foregroundServiceType="mediaProjection">_10 </service>_10</application>
_10 @Override_10 public void onCreate(Bundle savedInstanceState) {_10 super.onCreate(savedInstanceState);_10 setContentView(R.layout.activity_screen_capturer);_10 localVideoView = findViewById(R.id.local_video);_10 }
Get an instance of the MediaProjectionManager service. Call the createScreenCaptureIntent
method in a new activity. This initiates a prompt dialog for the user to confirm screen projection.
_10 private void requestScreenCapturePermission() {_10 Log.d(TAG, "Requesting permission to capture screen");_10 MediaProjectionManager mediaProjectionManager = (MediaProjectionManager)_10 getSystemService(Context.MEDIA_PROJECTION_SERVICE);_10_10 // This initiates a prompt dialog for the user to confirm screen projection._10 startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(),_10 REQUEST_MEDIA_PROJECTION);_10 }
Initialize the ScreenCapturer
class, after permission is received from the user. Create the LocalVideoTrack object and pass the ScreenCapturer
object to pass the captured local video frames. Set the VideoView
object to Visible
. Call the addSink
method on the LocalVideoTrack
object. Pass the VideoView
object to begin receiving the screen capture video.
_10 private void startScreenCapture() {_10 screenVideoTrack = LocalVideoTrack.create(this, true, screenCapturer);_10 screenCaptureMenuItem.setIcon(R.drawable.ic_stop_screen_share_white_24dp);_10 screenCaptureMenuItem.setTitle(R.string.stop_screen_share);_10_10 localVideoView.setVisibility(View.VISIBLE);_10 screenVideoTrack.addSink(localVideoView);_10 }
Found an error ? Open an issue on Github
Stuck on something? Can't find what you're looking for? Don't hesitate to contact Twilio Support through the Console or Help Center and we'll happily give you a hand.