Posted by Francesco Romano – Developer Relations Engineer on Android
App display screen sharing improves privateness and productiveness
Android 14 QPR2 brings thrilling developments in consumer privateness and streamlined multitasking with app display screen sharing. Now not do customers need to broadcast their total display screen whereas display screen sharing or casting, guaranteeing they share precisely what they wish to share.
Leverage the brand new MediaProjection APIs to customise the display screen sharing expertise and ship even higher utility to your customers.
What’s app display screen sharing?
Previous to Android 14, customers might solely share or document their total display screen on Android gadgets, which might expose personal data in different apps or notifications.
App display screen sharing is a brand new platform characteristic that lets customers prohibit sharing and recording to a single app window, mitigating the chance of oversharing personal messages or notifications. With app display screen sharing, the standing bar, navigation bar, notifications, and different system UI parts are excluded from the shared show. Solely the content material of the chosen app is shared.
This not solely enhances safety for display screen sharing, but in addition allows new use instances on massive screens. Customers can enhance multitasking productiveness – reminiscent of display screen sharing whereas attending a gathering – by profiting from further display screen house on these bigger gadgets.
How does it work?
There are three completely different entry factors for customers to start out app display screen sharing:
- Begin casting from Fast Settings
- Begin display screen recording from Fast Settings
- Launch from an app with display screen sharing or recording capabilities through the MediaProjection API
Let’s think about an instance the place a bunch consumer needs to share a single app to the members of a video name.
The host consumer begins display screen sharing as normal, however now in Android 14 they’re introduced with an up to date dialog that enables them to decide on whether or not to share a single app as a substitute of their total display screen.
The host consumer decides to share a single app, they usually choose the app from the App Selector.
Throughout display screen sharing, the video name members can see solely the content material from the chosen app.
The host consumer can finish the display screen seize in a number of methods: from the app the place sharing began, within the notification shade, by closing the app being shared, or by ending the video name.
Find out how to assist app display screen sharing?
Apps that use the MediaProjection APIs are able to beginning app display screen sharing with none code modifications. Nonetheless, it’s vital to check your app to make sure that the display screen sharing expertise works as meant, because the consumer circulation modifications with this new habits. Beforehand, the consumer would keep within the host app after the permission dialog. With app display screen sharing the consumer just isn’t returned to the host app, however the goal app to be shared is launched as a substitute. If the goal app was already working in foreground (e.g. in multi window mode), then it merely turns into the highest targeted app.
Android 14 additionally introduces two callback strategies to empower you to customise the sharing expertise:
MediaProjection.Callback#onCapturedContentResize(width, top) is invoked instantly after seize begins or when the scale of the captured area modifications. The tactic arguments present the correct sizing for the streamed seize.
Word: The given width and top correspond to the identical width and top that may be returned from android.view.WindowMetrics#getBounds() of the captured area.
If the recorded content material has a distinct side ratio from both the VirtualDisplay or output Floor, the captured stream has black bars across the recorded content material. The appliance can keep away from the black bars across the recorded content material by updating the scale of each the VirtualDisplay and output Floor:
override enjoyable onCapturedContentResize(width: Int, top: Int): String { // VirtualDisplay occasion from MediaProjection#createVirtualDisplay(). virtualDisplay.resize(width, top, dpi) // Create a brand new Floor with the up to date measurement. val textureName: Int // the OpenGL texture object title val surfaceTexture = SurfaceTexture(textureName) surfaceTexture.setDefaultBufferSize(width, top) val floor = Floor(surfaceTexture) // Make sure the VirtualDisplay has the up to date Floor to ship the seize to. virtualDisplay.setSurface(floor) }
The opposite API is MediaProjection.Callback#onCapturedContentVisibilityChanged(isVisible), which is invoked after seize begins or when the visibility of the captured area modifications. The tactic argument signifies the present visibility of the captured area.
The callback is triggered when:
- The captured area turns into invisible (isVisible==False).This may increasingly occur when the projected app just isn’t topmost anymore, like when one other app totally covers it, or the consumer navigates away from the captured app.
- The captured area turns into seen once more (isVisible==True).This may increasingly occur if the consumer strikes the masking app to point out no less than some portion of the captured app (for instance, the consumer has a number of apps seen in multi-window mode).
Functions can benefit from this callback by exhibiting or hiding the captured content material from the output Floor based mostly on whether or not the captured area is at present seen to the consumer. It is best to pause or resume the sharing accordingly so as to preserve assets.
How Google Meet is enhancing assembly productiveness
“App display screen sharing allows customers to share particular data in a Meet name with out oversharing personal data on the display screen like messages and notifications. Customers can select particular apps to share, or they can share the entire display screen as earlier than. Moreover, customers can leverage split-screen mode on massive display screen gadgets to share content material whereas nonetheless seeing the faces of pals, households, coworkers, and different assembly members.” – Product Supervisor at Google Meet
Let’s see app display screen sharing in motion throughout a video name, on this coming-soon model of Google Meet!
Window on the world
App display screen sharing opens doorways (and home windows) for extra targeted and safe app experiences inside the Android ecosystem.
This new characteristic enhances a number of use instances:
- Collaboration apps can facilitate targeted dialogue on particular design parts, paperwork, or spreadsheets with out together with distracting background particulars.
- Tech assist brokers can remotely view the consumer’s drawback app with out seeing probably delicate content material in different areas.
- Video conferencing instruments can share a presentation window selectively slightly than all the display screen.
- Academic apps can show performance with out compromising scholar privateness, and college students can share initiatives with out concern of exhibiting delicate data.
By thoughtfully implementing app display screen sharing, you possibly can set up your app as a champion of consumer privateness and comfort.