Posted by Francesco Romano – Android Developer Relations Engineer
Protect your privacy and increase productivity with app screen sharing
Android 14 QPR2 brings incredible advancements in user privacy and streamlined multitasking with app screen sharing. Users no longer need to broadcast their entire screen during screen sharing or casting, allowing them to share exactly what they want to share.
Take advantage of the new MediaProjection API to customize your screen sharing experience and provide even greater usability to your users.
What is app screen sharing?
Before Android 14, users could only share or record their entire screen on Android devices, which could expose personal information to other apps or notifications.
App screen sharing is a new platform feature that allows users to limit sharing and recording to a single app window, mitigating the risk of oversharing private messages or notifications. When you use app screen sharing, the status bar, navigation bar, notifications, and other system UI elements are excluded from the shared display. Only content from the apps you select will be shared.
This not only increases security for screen sharing but also enables new use cases on larger screens. Users can take advantage of the additional screen real estate on these larger devices to improve multitasking productivity, such as screen sharing while attending meetings.
How does it work?
There are three entry points for users to start sharing their app screen:
- Start transfer from quick settings
- Start screen recording from quick settings
- Run from apps with screen sharing or recording capabilities via the MediaProjection API
Consider an example where a host user wants to share a single app to video call participants.
The host user initiates screen sharing as usual, but now in Android 14 they’ll see an updated dialog that lets them choose whether to share a single app instead of the entire screen.
The host user decides to share a single app and selects the app from the app selector.
During screen sharing, video call participants can only view content from the app you select.
The host user has several ways to end the screen capture: from the app where the sharing was started, from the notification shade, by closing the app being shared, or by ending the video call.
How to support app screen sharing?
Apps that use the MediaProjection API can initiate sharing their app screen. without code changes. However, because this new behavior changes the user flow, it’s important to test your app to ensure that the screen sharing experience works as intended. Previously, users would remain in the host app beyond the permission dialog. App screen sharing does not take the user back to the host app, but instead launches the app you want to share with. If the target app is already running in the foreground (e.g. multi-window mode), that app becomes the highest focused app.
Android 14 also introduces two callback methods that allow you to customize your sharing experience.
MediaProjection.Callback#onCapturedContentResize(width, height) Called immediately after capture begins or when the size of the captured area changes. The method argument provides the exact size of the streaming capture.
memo: The given width and height are identical to the width and height returned by: android.view.WindowMetrics#getBounds() This is the captured area.
When the aspect ratio of the recorded content is different virtual display or output surface, there is a black bar around the recorded content of the captured stream. The application can update the size of both content to prevent black bars from appearing around the recorded content. virtual display and output surface:
override fun onCapturedContentResize(width: Int, height: Int): String { // VirtualDisplay instance from MediaProjection#createVirtualDisplay(). virtualDisplay.resize(width, height, dpi) // Create a new Surface with the updated size. val textureName: Int // the OpenGL texture object name val surfaceTexture = SurfaceTexture(textureName) surfaceTexture.setDefaultBufferSize(width, height) val surface = Surface(surfaceTexture) // Ensure the VirtualDisplay has the updated Surface to send the capture to. virtualDisplay.setSurface(surface) }
Other APIs MediaProjection.Callback#onCapturedContentVisibilityChanged(isVisible), called after capture has started or when the visibility of the captured area changes. The method argument indicates the current visibility of the captured area.
The callback is triggered when:
- The captured area becomes invisible. (isVisible==false).This can happen when the projected app is no longer at the top, for example, another app completely covers it, or the user moves away from the captured app.
- The captured area is displayed again. (isVisible==True).This can happen if the user moves the covering app to reveal at least part of the captured app (for example, when the user sees multiple apps in multi-window mode).
Applications can utilize this callback by showing or hiding captured content in the output. surface Determined by whether the captured area is currently visible to the user. To save resources, you should pause or resume sharing accordingly.
How Google Meet Improves Meeting Productivity
“App screen sharing allows users to share specific information in a Meet call without oversharing private information on their screen, such as messages or notifications. Users can select specific apps to share or share their entire screen like before. Additionally, users can take advantage of split-screen mode on large-screen devices to share content while seeing the faces of friends, family, colleagues, and other meeting participants. – Google Meet Product Manager
Let’s take a look at how app screen sharing works during video calls in the upcoming version of Google Meet.
window to the world
App screen sharing opens doors and windows for more focused and secure app experiences within the Android ecosystem.
This new feature improves several use cases.
- collaboration app You can foster focused discussions about specific design elements, documents, or spreadsheets without including distracting background details.
- technical support Agents can remotely view a user’s problematic app without having to see potentially sensitive content in other areas.
- video conferencing tools You can share the presentation window selectively rather than the entire screen.
- educational app You can demonstrate functionality without compromising student privacy, and students can share projects without fear of exposing sensitive information.
By thoughtfully implementing app screen sharing, you can position your app as an advocate for user privacy and convenience.