Posted by Francesco Romano – Developer Relations Engineer at Android
App screen sharing improves privacy and productivity
Android 14 QPR2 brings exciting advances in user privacy and streamlined multitasking with app screen sharing. Users no longer have to broadcast their entire screen when sharing or capturing a screen, ensuring that they share exactly what they want to share.
Use the new MediaProjection APIs to customize the screen sharing experience and deliver more value to your users.
What is App Screen Sharing?
Before Android 14, users could only share or record the entire screen on Android devices, which could expose personal information in 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, reducing the risk of sharing private messages or notifications. With app screen sharing, the status bar, navigation bar, notifications, and other parts of the system UI are excluded from the shared display. Only the content of the selected app is shared.
This not only provides security for screen sharing, but also enables new use cases on larger screens. Users can improve multitasking productivity – such as screen sharing while participating in a meeting – by taking advantage of the extra screen space on these larger devices.
How does it work?
There are three different entry points for users to start app screen sharing:
- Start taking from quick settings
- Start recording screen from quick settings
- Launch an app that has screen sharing or recording capabilities via the MediaProjection API
Consider an example where a host user wants to share an application with video call participants.
The host user starts sharing their screen as usual, but now in Android 14 they have an updated dialog that allows them to choose to share an app or share instead of their entire screen.
The host user decides to share an app and selects the app from the app picker.
During screen sharing, video call participants can only see content from the selected app.
The host user can end the screen recording in a few ways: from the app where the sharing was started, in 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 APIs can initiate app screen sharing. Without changing any code. However, since the user flow will change with this new feature, it's important to test your app to make sure the screen sharing experience works as intended. Previously, the user remained in the host application after the permission dialog. With app screen sharing, the user is not returned to the host app, but the target app to be shared is launched instead. If the target app is already running in the foreground (eg in multi-window mode), it simply becomes the top-focused app.
Android 14 introduces two callbacks to let you customize the sharing experience:
MediaProjection.callback# per contentContentSize(width, height) It is checked immediately after the recording is started or when the captured area is resized. The method arguments provide the correct size for the stream capture.
Note: The given width and height correspond to the same width and height returned android.view.WindowMetrics#getBounds() The occupied territory.
If the recorded content has a different aspect ratio Virtual display or output Floor, the captured stream has black bars around the recorded content. The application can update the size of both and remove the black bars around the recorded content. Virtual display and output Floor:
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) }
Another is the API. MediaProjection.callback#withContentViewChanged(visible), which is called after capturing or when the visibility of the captured region changes. The method argument indicates the current visibility of the occupied region.
The callback starts with:
- The captured region will be invisible. (visible==false)This can happen when the targeted app is no longer on top, like when another app completely covers it, or when the user moves away from the occupied app.
- The reserved area will be displayed again (shown = true)This can happen if the user moves the overlaying app to show at least part of the captured app (for example, the user has multiple apps displayed in multi-window mode).
Applications can use this callback to show or hide the formatted content from the output. Floor Depending on whether the reserved region is currently visible to the user. You should pause sharing accordingly to save resources.
How Google Meet is improving meeting productivity.
“App screen sharing allows users to share specific information on a Meet call without sharing too much personal information, such as messages and notifications, on the screen. Users can choose specific apps to share or share the entire screen as before. Users can also share information with friends, family, colleagues, and other members of the meeting.” You can use screen mode on large-screen devices to share content while facing participants. – Product manager on Google Meet
Let's see app screen sharing during a video call in action, in this upcoming version of Google Meet!
A window on the world
App screen sharing opens doors (and windows) to more focused and secure app experiences in the Android ecosystem.
This new feature improves several use cases:
- Collaborative applications It can facilitate focused discussion on specific design elements, documents, or spreadsheets without including distracting background details.
- Technology support Agents can remotely view a user's problem app without viewing sensitive content in other locations.
- Video conference equipment Can select and share a presentation window instead of the entire screen.
- Educational applications It can demonstrate functionality without compromising student privacy, and students can share projects without fear of revealing sensitive information.
By carefully implementing app screen sharing, you can establish your app as a champion of user privacy and convenience.